运行以下代码给我一个错误:
由于内存不足,.NET Framework 执行被升级策略中止。System.InvalidOperationException:已经有一个打开的 DataReader 与此命令关联,必须先关闭。
我到处都有以下代码来运行我的sql:
sql.Append(string.Format("SELECT TableId FROM ps_SavedTables WHERE guid = '{0}'", guid));
using (IDataReader reader = SqlHelper.GetDataReader(sql.ToString())) {
if (reader.Read()) {
result = reader.IsDBNull(0) ? string.Empty : reader[0].ToString();
}
//CDW added to close SqlDataReader
reader.Close();
}
GetDataReader 由以下定义:
public static SqlDataReader GetDataReader(string sql, string connectionString) {
lock (_lock) {
SqlConnection connection = null;
try {
connection = GetConnection(connectionString);
//connection.Open();
using (SqlCommand cmd = new SqlCommand(sql, connection)) {
WriteDebugInfo("GetDataReader", sql);
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
}
catch (Exception e) {
if (connection != null)
connection.Dispose();
throw new DataException(sql, connectionString, e);
}
}
}