中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Visual C++ > 数据库操作
VC编译ADO的开发环境和客户环境的细微差别可能导致的失败
作者:zhengyun_ustc 时间:2001-10-07 09:59 出处:互联网 责编:chinaitpower
              摘要:VC编译ADO的开发环境和客户环境的细微差别可能导致的失败
·应阅读本公告牌的目标受众:针对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:
请一定参考这篇文档,他们抱怨得非常清楚:
> 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(原作)
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有