运行时显示createinstance of connection fail!,已经初始化过COM环境了,这是怎么回事?
HRESULThr;try{//实例化连接对象hr=m_pConnection.CreateInstance(_uuidof(Connection));if(SUCCEE...
HRESULT hr;
try
{
//实例化连接对象
hr=m_pConnection.CreateInstance(_uuidof(Connection));
if (SUCCEEDED(hr))
{
//设置连接串属性为UDL文件
m_pConnection->ConnectionString="File Name=ddd.udl";
//设置等待连接打开的时间为20s
m_pConnection->ConnectionTimeout=20;
hr=m_pConnection->Open("","","",adConnectUnspecified);
if (FAILED(hr))
{
AfxMessageBox("open fail!");
return TRUE;
}
else
{
AfxMessageBox("createinstance of connection fail!");
return TRUE;
}
}
}
catch (_com_error e)
{
//给出异常信息
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
AfxMessageBox(bstrSource+bstrDescription);
return TRUE;
} 展开
try
{
//实例化连接对象
hr=m_pConnection.CreateInstance(_uuidof(Connection));
if (SUCCEEDED(hr))
{
//设置连接串属性为UDL文件
m_pConnection->ConnectionString="File Name=ddd.udl";
//设置等待连接打开的时间为20s
m_pConnection->ConnectionTimeout=20;
hr=m_pConnection->Open("","","",adConnectUnspecified);
if (FAILED(hr))
{
AfxMessageBox("open fail!");
return TRUE;
}
else
{
AfxMessageBox("createinstance of connection fail!");
return TRUE;
}
}
}
catch (_com_error e)
{
//给出异常信息
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
AfxMessageBox(bstrSource+bstrDescription);
return TRUE;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询