Multi-threaded MSSQL dbExpress Driver Usage

By: Steven Shaughnessy

Abstract: For multi-threaded usage of the Delphi 2007 MSSQL dbExpress driver the COM coinitialize and couninitialize should be called for all threads that use this driver.

The Microsoft SQL Server dbExpress driver will automatically call coinitialize when the driver is loaded. If this initial call to counitialize succeeds, the driver will also:

  1. Call couninitialize when the driver is unloaded.
  2. Call coinitialize when a new connection is made.
  3. Call counitialize when a connection is closed.

The apartment threading model is used to all automatic calls to coinitialize made by the driver.

If a different threading model is needed, or there are any other problems using this driver with a multiple threaded application, it is best it the application calls coinitialize and counitialize for all threads that use this driver:

  1. Call coinitialize when the application starts and couninitialize before the application exits.
  2. Call coinitialize when a secondary thread starts and couninitialize before the secondary thread exits.

Server Response from: ETNASC03