C# 如果筛选条件从10天扩展到整月,则数据集填充为null。OutOfMemory异常
当我从SQLServer2012为多达100万行填充数据集时,一切正常。但当我减少筛选条件并从SQLServer中选择大约300万行到数据集中时,我得到的数据集对象为nullC# 如果筛选条件从10天扩展到整月,则数据集填充为null。OutOfMemory异常,c#,sql-server-2012,dataset,C#,Sql Server 2012,Dataset,当我从SQLServer2012为多达100万行填充数据集时,一切正常。但当我减少筛选条件并从SQLServer中选择大约300万行到数据集中时,我得到的数据集对象为null public DataSet ExecDataSet(string sql) { try { using (SqlCommand cmd = new SqlCommand()) {
public DataSet ExecDataSet(string sql)
{
try
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = connection;
cmd.CommandTimeout = commandTimeout;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
return ExecDataSet(cmd);
}
}
catch (Exception ex)
{
lastErrorMsg = ex.Message;
return null;
}
}
从您的帖子描述来看,由于代码语句
cmd.CommandTimeout=CommandTimeout,用于获取3M行的查询似乎正在超时代码>并因此引发超时
异常,并到达Catch()
块,在该块中返回null
,如下所示
catch (Exception ex)
{
lastErrorMsg = ex.Message;
return null;
}
尝试增加超时值,看看是否成功。debug,在catch
设置断点,并发布异常消息ExecDataSet(cmd)
???是接受命令参数的重载吗?我想我应该通过扩展Commandtimeout来尝试。抱歉,伙计,这实际上是一个outofmemory例外。在Dataadapter.Fill(数据集)处。