我正在运行 .NET 3.5 (C#) 和 SQL Server 2005(针对我们的客户)。我们运行的代码做了一些回归数学,有点复杂。当我在我们的网站上运行多个页面时出现以下错误:
.NET Framework execution was aborted by escalation policy because of out of memory.
System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
System.InvalidOperationException:
我试图找出造成这种情况的根本原因:是数据库问题还是我的 C## 代码?还是在运行查询时与锁并发?还是别的什么?
代码在这里出错:
erver.ScriptTimeout = 300;
string returnCode = string.Empty;
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MainDll"].ToString())) {
connection.Open();
using (SqlCommand command = new SqlCommand(sql.ToString(), connection)) {
command.CommandType = CommandType.Text;
command.CommandTimeout = 300;
returnCode = (string)command.ExecuteScalar();
//Dispose();
}
//Dispose();
}
我们的承包商在 App_Code/sqlHelper.s 文件中编写了一堆代码来帮助处理 SQL 连接。其中一些是这样的:
public static SqlDataReader GetDataReader(string sql, string connectionString, int connectionTime) {
lock (_lock) {
SqlConnection connection = null;
try {
connection = GetConnection(connectionString);
//connection.Open();
using (SqlCommand cmd = new SqlCommand(sql, connection)) {
cmd.CommandTimeout = connectionTime;
WriteDebugInfo("GetDataReader", sql);
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
}
catch (Exception e) {
if (connection != null)
connection.Dispose();
throw new DataException(sql, connectionString, e);
}
}
}
是否应该在某处释放一些内存?