Note that there are some explanatory texts on larger screens.

plurals
  1. POExecuteNonQuery in parallel within a shared OleDbConnection / OleDbTransaction
    primarykey
    data
    text
    <p>Discovered that OleDBConnection doesn't seem to be ThreadSafe. It appears that it attempts to open multiple connections instead.</p> <pre><code>//doesn't work using (OleDbConnection oConn = TheDataAccessLayer.GetConnection()) using (OleDbTransaction oTran = oConn.BeginTransaction()) Parallel.ForEach(ORMObjects, (ORMObject, State) =&gt; { if (!State.ShouldExitCurrentIteration &amp;&amp; !State.IsExceptional) { var Error = ORMObject.SomethingThatExecutesANonQuery(oConn,oTran) if (Error.Number != 0) State.Stop(); } }); </code></pre> <p>If I lock the connection for an ExecuteNonQuery the errors go away, but the performance tanks.</p> <pre><code> //works using (OleDbConnection oConn = TheDataAccessLayer.GetConnection()) using (OleDbTransaction oTran = oConn.BeginTransaction()) Parallel.ForEach(ORMObjects, (ORMObject, State) =&gt; { if (!State.ShouldExitCurrentIteration &amp;&amp; !State.IsExceptional) { lock(oConn) { var Error = ORMObject.SomethingThatExecutesANonQuery(oConn,oTran) if (Error.Number != 0) State.Stop(); } } }); </code></pre> <p>Assume that </p> <ul> <li><p>I can't change the nature of the ORM: the SQL cannot be bulked</p></li> <li><p>Business rules require that the interaction be performed within a single transaction</p></li> </ul> <p>So:</p> <ul> <li><p>Is there a more better/more efficient way to parallelize OleDb interactions?</p></li> <li><p>If not, is there an alternative to the OleDb client that can take full advantage of parallelism? (Maybe the native MSSQL client?)</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload