·应阅读本公告牌的目标受众:针对Microsoft®ADO 2.5及其后续版本加以应用的客户。这其中便包括使用着Microsoft Windows® XP、SQL Server™ 2000和MDAC 2.7的VC程序员。
·薄弱环节可能造成的影响:VC编译的应用运行失败。
·现象:
在开发机器上编译如下代码:
#pragma warning(push) // Needs to be done in order to suppress warning message
#pragma warning(disable:4146) // caused by bug in ADO (MS Knowledge Base article Q253317)
#import "C:\Program Files\Common Files\system\ado\msado15.dll" \
no_namespace rename("EOF","adoEOF")
#pragma warning(pop)
.....
_CommandPtr pCmd = NULL;
HRESULT hr = pCmd.CreateInstance("ADODB.Command");
但是在客户的一台正常的Windows2000上却发生错误:
Command指针创建失败,错误号:0x80004002,错误描述:没有此接口。
·原因:
我们的开发机器上一般都装有MDAC2.7,这可能是因为装了SQL Server,也可能是WinXP自带的。
而客户机器上只有MDAC2.5。
由于微软的ADO开发小组习惯上总把ADO的最新版本命名为默认接口,如ADO2.5时将_Command25命名为_Command。
这样当你在MDAC2.7下编译VC代码,绑定的_Command的InterfaceID可能就是_Command2.7的接口ID。而在客户的MDAC2.5环境中
,可能不存在这个接口ID,它的_Command的接口ID还是2.5的,和你的机器上的_Command接口ID肯定不一样。
所以以VC的方式创建_CommandPtr指针,是无法创建出来的。但是由于VB并不是绑定InterfaceID,所以VB中还可以正常创建ADO接口指针。
·解决方法:
第一种:只在MDAC2.5环境下编译,并发布到MDAC2.5以上的客户环境中,但是WindXP就没有办法了;
第二种:强迫客户环境升级MDAC;
第三种:在MDAC2.7环境下编译,但是我们只明确表示创建Command25指针,如下所示:
ADODB::
Command25Ptr pCmdChange = NULL;
HRESULT hResult = pCmdChange.CreateInstance(__uuidof(ADODB::Command));
第四种:选择使用OLEDB;
============================================
·参考1:
请一定参考这篇文档,他们抱怨得非常清楚:
http://groups.google.com/groups?q=b08400bd+command&hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=uwaoAXD7BHA.1864%40tkmsftngp04&rnum=1
> The call to CreateInstance will fail when the code is
> compiled with a MDAC 2.7 version of msado.dll but run on
> a system with MDAC 2.5 installed. It returns a HRESULT of
> 0x80004002 (E_NOINTERFACE) - "The QueryInterface method
> did not recognize the requested interface. The interface
> is not supported.". i.e. the code tried to find the new
> _Command interface NOT the old _Command interface as
> defined in MDAC 2.5.
> The code works fine when compiled with MDAC 2.5 and run
> on a system with MDAC 2.5 or greater. (Will also work
> fine when compiled with MDAC 2.7 and run on MDAC 2.7).
>
> SOLUTIONS
> ------------------
>
> 1) Compile only on MDAC 2.5 and then can target MDAC 2.5
> or greater (Not really an option with Windows XP (.NET
> etc.))
>
> 2) Compile with MDAC 2.7 and force all clients to upgrade
> to MDAC 2.7 (Not an ideal solution as already have enough
> problems when forcing clients to install MDAC 2.5 -
> breaking existing apps - or simply not installing
> properly as part of the install process)
>
> 3) The solution we have come up with is to develop on
> systems with MDAC 2.7 installed but not to use
> the "_Command" interface. Instead we use the "Command25"
> interface (i.e. this is the renamed "_Command" interface
> from MDAC 2.5). This means all our developers are forced
> to develop on MDAC 2.7 but we can continue to target MDAC
> 2.5 or better). i.e. the above code becomes
>
> ADODB::Command25Ptr pCmdChange = NULL;
> HRESULT hResult = pCmdChange.CreateInstance
> (__uuidof(ADODB::Command));
=============================
·参考2:
另一篇中文参考:
我的ATL/ADO编程的曲折经历 horris(原作)
http://www.csdn.net/develop/article/14/14662.shtm
本文地址:http://com.8s8s.com/it/it2110.htm