Issues to be aware of using unidac+mssql under multithreading (using CoInitialize)

Source: Internet
Author: User
Tags mssql

The ADO thread is not secure and UNIDAC is using MSSQL as well. Actually this is Microsoft COM problem, not blame Devart company.

The general workaround is to start CoInitialize (nil) on the thread and end the call to CoUninitialize. If you use a variety of database connections, such as the three layer often switch to MSSQL and Oracle, we only need to determine the Tuniconnection connection before the event Onbeforeconnect write down the following code:

Procedure Tservdbfunc.servconnbeforeconnect (Sender:tobject);
Begin
if (Servconn <> nil) and Sametext (Servconn.providername, ' SQL Server '); then
CoInitialize (nil);
End

After the Tuniconnection closed connection event Onafterdisconnect write the following code:

Procedure Tservdbfunc.servconnafterdisconnect (Sender:tobject);
Begin
if (Servconn <> nil) and Sametext (Servconn.providername, ' SQL Server '); then
CoUninitialize;
End

Note that you must first determine if the connection control (Servconn <> nil) is empty, otherwise you will fall into the issue of pointer release.

Transferred from: http://hi.baidu.com/tintinsoft/item/361a8255237b0dc49f266761

http://blog.csdn.net/rznice/article/details/8252775

Issues to be aware of using unidac+mssql under multithreading (using CoInitialize)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.