[ADO] how to modify the thread model of ADO

Source: Internet
Author: User
By default, ADO is the Apartment thread model.
 

  If you are using this in IIS and ADO is only being used at page scope 
then it should be fine. 
If you are using it at the session or application level then you will 
need to mark it as both.  

 

So how can we change it to Both?

It may be to change the thread model in the registry.

 

In

C:/Program Files/Common Files/System/ado

There are two reg files in the folder, which is interesting.

ADOFRE15.REG

ADOAPT15.REG

 

Where,ADOFRE15.REGThis is the content:

REGEDIT4

 

[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000507-0000-0010-8000-00AA006D2EA4}/InprocServer32]
"ThreadingModel" = "Both"

 

[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000514-0000-0010-8000-00AA006D2EA4}/InprocServer32]
"ThreadingModel" = "Both"

 

[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{0000050B-0000-0010-8000-00AA006D2EA4}/InprocServer32]
"ThreadingModel" = "Both"

 

[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000535-0000-0010-8000-00AA006D2EA4}/InprocServer32]
"ThreadingModel" = "Both"

 

[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000541-0000-0010-8000-00AA006D2EA4}/InprocServer32]
"ThreadingModel" = "Both"

 

okay, you'll see that the ThreadingModel is adjusted for the following 
coclasses:

 

1. Command

2. Connection

3. Parameter

4. Recordset

5. Error

 

If the threading model selected is "Apartment" (the default), then the

objects listed above can be accessed only by the thread created it.  If

threading model is "Both" and the object is created in an STA, then all

access to it will through the single thread that runs in the STA. If

threading model is "Both" and the object is created in an MTA, then any

thread in this MTA will have direct access to it.

 

If the objects integrate FTM (I don't know whether ADO does this or not),

then different threads in different apartments will have direct access to

the objects (without proxies).

Or refer to the authoritative Microsoft document:Http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/cpguide/html/cpconvisualbasic#agechanges. asp

You can configure ADO. NET to use the free-threaded model by importing the following registry data. to modify the registry, copy this data to a REG file (such as Adofre. reg) and import it using the Regedit.exe program(for example, Regedit /s Adofre.reg).

The following registry information is wrongly ded on Windows 2000 and Windows Server 2003 systems in the Adofre15.reg file. the batch file Makfre15.bat updates the registry with the information in Adofre15.reg. both files are located in Program Files/Common Files/System/ado /.

REGEDIT4[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000507-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Both"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000514-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Both"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{0000050B-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Both"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000535-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Both"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000541-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Both"

If you do not plan to use ADO. NET from ASP. NET applications, you can use the apartment threading model for better ADO. NET performance with legacy applications such as those created with Visual Basic version 6. you can configure apartment threading by importing the following registry data. to modify the registry, copy this data to a REG file (such as Adoapt. reg) and import it using the Regedit.exe program.

The following registry information is wrongly ded on Windows 2000 and Windows Server 2003 systems in the Adoapt15.reg file. the Makapt15.bat batch file updates the registry with the information in Adoapt15.reg. both files are located in/Program Files/Common Files/System/ado /.

REGEDIT4[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000507-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Apartment"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000514-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Apartment"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{0000050B-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Apartment"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000535-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Apartment"[HKEY_LOCAL_MACHINE/SOFTWARE/Classes/CLSID/{00000541-0000-0010-8000-00AA006D2EA4}/InprocServer32]"ThreadingModel"="Apartment"
For more information, see:

Http://www.faqchest.com/msdn/DCOM/dcom-00/dcom-0011/dcom00112713_21236.html

Date: Mon, 27 Nov 2000 13:31:04-0500
From: Hitesh Mittal
Subject: Re: Changing threading model of ADO.

Go to c:/programfiles/common files/system/ado
You shoshould see adoapt15.reg and adofre15.reg. Run one of these to register
Apartment or Both.
There is nothing wrong in changing the apartment model to Both, the objects
Will be created in the same apartment as the thread is initialized.
Hitesh Mittal

 

Thanks to Alex Matevossian and Jim Cirone.

Zhengyun (at) tomosoft.com.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? PostId = 12728

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.