这是我数据库连接的代码
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance(__uuidof(Connection));//创建Connection对象 if(SUCCEEDED(hr))
{
m_pConnection->ConnectionString="File Name=my_data.udl";
// m_pConnection->ConnectionTimeout=3;//设置超时时间为3秒
hr=m_pConnection->Open("","","",adConnectUnspecified);
if(FAILED(hr))
{
AfxMessageBox("Open Fail!");
return false;
}
}
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;
}
编译没有报错但是总是在运行的时候就弹出Createinstance of Connection fail! 消息
我不明白 数据库连接失败?? 我已经初始化了COM库 为什么没进到If语句中呢? 望高手指点!
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance(__uuidof(Connection));//创建Connection对象 if(SUCCEEDED(hr))
{
m_pConnection->ConnectionString="File Name=my_data.udl";
// m_pConnection->ConnectionTimeout=3;//设置超时时间为3秒
hr=m_pConnection->Open("","","",adConnectUnspecified);
if(FAILED(hr))
{
AfxMessageBox("Open Fail!");
return false;
}
}
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;
}
编译没有报错但是总是在运行的时候就弹出Createinstance of Connection fail! 消息
我不明白 数据库连接失败?? 我已经初始化了COM库 为什么没进到If语句中呢? 望高手指点!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货