当我的程序逐步执行字典并插入记录时,我的内存使用量会逐渐增加,直到我的代码失败。我从一开始就打开与Oracle的连接,然后在整个过程中仅重用同一连接。因此,用一个大的插入语句(大约100,000次)调用以下代码会导致内存不足异常。我不确定该如何重置?
C#:
public int ExecuteNonQuery(string sql) {
try
{
//conn.Open();
int affected;
//Debug.WriteLine("Connection: " + this.conn.InstanceName);
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
cmd.Connection = conn;
affected = cmd.ExecuteNonQuery();
//mytransaction.Commit();
return affected;
}
catch (Exception ex)
{
Console.WriteLine("OracleDataAccessManager.ExecuteNonQuery(): " + ex);
throw ex; //Acts the same as a return.
}
finally
{
//conn.Close(); //Not using this section
}
}