OleDbException System Resources Exceeded

后端 未结 5 759
感动是毒
感动是毒 2020-12-11 04:07

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 Ex

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 04:41

    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();
            }
        }
    }
    

提交回复
热议问题