OleDbException System Resources Exceeded

Pauly picture Pauly · Oct 1, 2008 · Viewed 15.2k times · Source

The following code executes a simple insert command. If it is called 2,000 times consecutively (to insert 2,000 rows) an OleDbException with message = "System Resources Exceeded" is thrown. Is there something else I should be doing to free up resources?

using (OleDbConnection conn = new OleDbConnection(connectionString))
using (OleDbCommand cmd = new OleDbCommand(commandText, conn))
{
    conn.Open();
    cmd.ExecuteNonQuery();
}

Answer

FlySwat picture FlySwat · Oct 1, 2008

The system resources exceeded error is not coming from the managed code, its coming from you killing your database (JET?)

You are opening way too many connections, way too fast...

Some tips:

  • Avoid round trips by not opening a new connection for every single command, and perform the inserts using a single connection.
  • Ensure that database connection pooling is working. (Not sure if that works with OLEDB connections.)
  • Consider using a more optimized way to insert the data.

Have you tried this?

using (OleDBConnection conn = new OleDBConnection(connstr))
{
    while (IHaveData)
    {
        using (OldDBCommand cmd = new OldDBCommand())
        {
            cmd.Connection = conn;
            cmd.ExecuteScalar();
        }
    }
}