Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6742375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:50:09+00:00 2026-05-26T11:50:09+00:00

Discovered that OleDBConnection doesn’t seem to be ThreadSafe. It appears that it attempts to

  • 0

Discovered that OleDBConnection doesn’t seem to be ThreadSafe. It appears that it attempts to open multiple connections instead.

//doesn't work
using (OleDbConnection oConn = TheDataAccessLayer.GetConnection())
using (OleDbTransaction oTran = oConn.BeginTransaction())
Parallel.ForEach(ORMObjects, (ORMObject, State) =>
{

        if (!State.ShouldExitCurrentIteration && !State.IsExceptional)
        {
              var Error = ORMObject.SomethingThatExecutesANonQuery(oConn,oTran)

              if (Error.Number != 0)
                  State.Stop();

        }

});

If I lock the connection for an ExecuteNonQuery the errors go away, but the performance tanks.

 //works
    using (OleDbConnection oConn =  TheDataAccessLayer.GetConnection())
    using (OleDbTransaction oTran = oConn.BeginTransaction())
    Parallel.ForEach(ORMObjects, (ORMObject, State) =>
    {

            if (!State.ShouldExitCurrentIteration && !State.IsExceptional)
            {
              lock(oConn)
              {
                    var Error = ORMObject.SomethingThatExecutesANonQuery(oConn,oTran)

                if (Error.Number != 0)
                      State.Stop();
             }

            }

    });

Assume that

  • I can’t change the nature of the ORM: the SQL cannot be
    bulked

  • Business rules require that the interaction be performed within a single transaction

So:

  • Is there a more better/more efficient way to parallelize OleDb interactions?

  • If not, is there an alternative to the OleDb client that can take full advantage of parallelism? (Maybe the native MSSQL client?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:50:10+00:00Added an answer on May 26, 2026 at 11:50 am

    Transactions need to be ACID, but the “Durability” needs to be enforced only at the transaction’s end. So physical IO to the disk may be postponed after the apparent SQL statement execution and actually done in the background, while your transaction is processing other statements.

    As a consequence, issuing SQL statements serially may not be much slower than issuing them concurrently. Consider this scenario:

    • Execute the SQL statement [A] that writes data. The disk is not actually touched, writes are simply queued for later, so the execution flow returns very quickly to the client (i.e. [A] does not block for long).
    • Execute the SQL statement [B] that writes data. Writes are queued and [B] does not block for long, just as before. The physical I/O of [A] may already be happening in the background at this point.
    • Other processing takes place in the transaction, while DBMS performs the physical I/O to the disk in the background.
    • The transaction is committed.
      • If queued writes are finished, there is no need to wait.
      • If queued writes are not finished by now, wait until they are. BTW, some databases can relax the “Durability” requirements to avoid this wait, but not MS SQL Server (AFAIK).

    Of course there are scenarios where this “auto-parallelism” of DBMS would not work well, for example when there is a WHERE clause that for different statements touches different partitions on different disks – DBMS would love to parallelize these clauses but can’t if they are fed to it one-by-one.

    In any case, don’t guess where your performance bottleneck is. Measure it instead!


    BTW, MARS will not help you in parallelizing your statements – according to MSDN: “Note, however, that MARS is defined in terms of interleaving, not in terms of parallel execution.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just discovered that using <div /> instead of <div></div> completely destroys my page
recently I discovered that executing a C program as a release build instead of
I just discovered that the Delphi TRibbonComboBox doesn't have an item index, and it
I have just discovered that SQL Server CE doesn't allow you to batch queries.
I just discovered that empty() does not work when passing data from an object.
I discovered that one of the tables of a legacy db I'm working on
I discovered that it is possible to extract the hard-coded strings from a binary.
We recently discovered that the Google Maps API does not play nicely with SSL.
Today I discovered that my fresh installation of Apache HTTP Server is able to
I've discovered that any time I do the following: echo '<a href=http:// title=bla>huzzah</a>'; I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.