MFC使用ADO连接SQL2005时出现问题
程序在编译可以成功,但是运行时就会出现问题。下面是我的代码:voidCDbAdoDlg::OnBnClickedSelect(){CoInitialize(NULL);/...
程序在编译可以成功,但是运行时就会出现问题。下面是我的代码:
void CDbAdoDlg::OnBnClickedSelect()
{
CoInitialize(NULL); //初始化COM库
_ConnectionPtr pConn(__uuidof(Connection)); //实例化智能指针对象
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=yj;Initial Catalog=test;Data Source=YANGJUN-PC\SQLEXPRESS";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select * from test",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize(); //释放COM库
}
进行分布执行时,在运行到以下两句时会出现问题。
pConn->ConnectionString ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=yj;Initial Catalog=test;Data Source=YANGJUN-PC\SQLEXPRESS";
pConn->Open("","","",adConnectUnspecified); 展开
void CDbAdoDlg::OnBnClickedSelect()
{
CoInitialize(NULL); //初始化COM库
_ConnectionPtr pConn(__uuidof(Connection)); //实例化智能指针对象
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=yj;Initial Catalog=test;Data Source=YANGJUN-PC\SQLEXPRESS";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select * from test",NULL,adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString(
(_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize(); //释放COM库
}
进行分布执行时,在运行到以下两句时会出现问题。
pConn->ConnectionString ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=yj;Initial Catalog=test;Data Source=YANGJUN-PC\SQLEXPRESS";
pConn->Open("","","",adConnectUnspecified); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询