VC编译ADO的开发环境和客户环境的细微差别可能导致的失败 (转)

VC编译ADO的开发环境和客户环境的细微差别可能导致的失败 (转)[@more@]
·应阅读本公告牌的目标受众:针对 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 FilesCommon Filessystemadomsado15.dll"
 no_namespace rename("EOF","adoEOF")
#pragma warning(pop)
.....
_CommandPtr pCmd = NULL;
HRESULT hr = pCmd.CreateInstance("ADO db.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:
请一定参考这篇文档,他们抱怨得非常清楚:
google.com/groups?q=b08400bd+command&hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=uwaoAXD7BHA.1864%40tkm sftngp04&rnum=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
> pro perly 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

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-977284/,如需转载,请注明出处,否则将追究法律责任。

user_pic_default.png
请登录后发表评论 登录
全部评论
<%=items[i].createtime%>

<%=items[i].content%>

<%if(items[i].items.items.length) { %>
<%for(var j=0;j
<%=items[i].items.items[j].createtime%> 回复

<%=items[i].items.items[j].username%>   回复   <%=items[i].items.items[j].tousername%><%=items[i].items.items[j].content%>

<%}%> <%if(items[i].items.total > 5) { %>
还有<%=items[i].items.total-5%>条评论 ) data-count=1 data-flag=true>点击查看
<%}%>
<%}%>
<%}%>

转载于:http://blog.itpub.net/10752019/viewspace-977284/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值