VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
[ADO]如何修改ADO的线程模型

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

ADO缺省情况下当然是Apartment线程模型。
  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.  

 

那么怎么改为Both呢?

可能就是改一下注册表里面的线程模型。

 

C:\Program Files\Common Files\System\ado

文件夹下,有两个reg文件,很有趣,可能就是这个意思。

ADOFRE15.REG

ADOAPT15.REG

 

其中,ADOFRE15.REG就是这个内容:

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).
或者参见权威的微软文档:

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 included 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 included 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"
 或者参见:

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 <[PRIVACY PROTECTION]>
Subject: Re: Changing threading model of ADO.

go to c:\programfiles\common files\system\ado
you should 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 with.
Hitesh Mittal

 

感谢Alex MatevossianJim Cirone

Zhengyun (at) tomosoft.com 收藏。




相关文章

相关软件