您的位置:首页 > 产品设计 > UI/UE

CreateInstance(__uuidof(Connection)) 不支持此接口解决方法

2014-12-08 16:46 417 查看

bool CAdoMethod::OpenDatabase(CString dbIP, CString dbKey, CString dbName)

{

CString my_connect;

my_connect.Format("Provider=sqloledb;server=%s;database=%s", dbIP, dbName);

HRESULT hr;

try

{

hr = m_pConnection.CreateInstance(__uuidof(Connection));//CreateInstance("ADODB.Connection");

if (SUCCEEDED(hr))

{

hr = m_pConnection->Open((LPCTSTR)my_connect, "sa", (_bstr_t)dbKey, adModeUnknown);

if (SUCCEEDED(hr))

m_IsConnection = true;

else

AfxMessageBox("m_pConnection->Open失败");

}else{

_com_error e(hr);

AfxMessageBox(e.ErrorMessage());

}

}

catch(_com_error e)///捕捉异常

{

m_IsConnection = FALSE;

_bstr_t bstrDescription(e.Description());

TRACE("Exception thrown for classes generated by #import");

TRACE("\t Description = %s \n", (LPCTSTR)bstrDescription);

AfxMessageBox(bstrDescription);

}

return m_IsConnection;

}

刚开始在win7上编译运行没有问题,但是程序拷贝到xp上就出现 不支持此接口的错误提示,找了半天找到原因了,主要是msado15.dll版本不同,在stdafx.h中,

#import "C:\Program Files\Common Files\System\ado\msado15.dll" \

no_namespace rename("EOF", "adoEOF")

此处编译进去的是win7的msado15.dll,当然在xp上没法运行。

解决方法:将xp下的C:\Program Files\Common Files\System\ado\msado15.dll拷贝到win7下相应目录重新编译即可(记得备份啊)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐