VC編譯ADO的開發環境和客戶環境的細微差別可能導致的失敗 (轉)

amyz發表於2007-10-17
VC編譯ADO的開發環境和客戶環境的細微差別可能導致的失敗 (轉)[@more@]
·應閱讀本公告牌的目標受眾:針對®ADO 2.5及其後續版本加以應用的客戶。這其中便包括使用著Microsoft ® XP、 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 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.Command");
但是在客戶的一臺正常的上卻發生錯誤:
Command指標建立失敗,錯誤號:0x80004002,錯誤描述:沒有此介面。
 
·原因:
我們的開發機器上一般都裝有MDAC2.7,這可能是因為裝了,也可能是自帶的。
而客戶機器上只有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:
請一定參考這篇文件,他們抱怨得非常清楚:
.com/groups?q=b08400bd+command&hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=uwaoAXD7BHA.1864%40tkmtngp04&rnum=1">%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 (
> etc.))
>
> 2) Compile with MDAC 2.7 and force all clients to upgrade
> to MDAC 2.7 (Not an al solution as already have enough
> problems when forcing clients to install MDAC 2.5 -
> breaking existing apps - or simply not installing
> proy 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(原作)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-977284/,如需轉載,請註明出處,否則將追究法律責任。

VC編譯ADO的開發環境和客戶環境的細微差別可能導致的失敗 (轉)
請登入後發表評論 登入
全部評論

相關文章