各位大虾,我编写的一个数据库ado链接,,编译链接通过了,,运行的时候报错,,runtime error,,各位达人帮我找找原因啊,,感激不尽,核心代码如下:void CAdoDlg::OnBtnQuery() 
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr  pRst(__uuidof(Recordset)); pConn->ConnectionString="Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=hswinrun2;Initial Catalog=hswinrun2Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=hswinrun2;Initial Catalog=hswinrun2";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select * from entrusts",NULL,adCmdText);
while(!pRst->rsEOF)
{
    ((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("l_workgroup_id"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}

解决方案 »

  1.   


    try
    {
    pConn->ConnectionString="Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=hswinrun2;Initial Catalog=hswinrun2Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=hswinrun2;Initial Catalog=hswinrun2";
    pConn->Open("","","",adConnectUnspecified);
    }catch(_com_error e)
    {
    MessageBox(NULL, e.Description(), e.ErrorMessage(), MB_OK);}看下什么提示。
      

  2.   

    pConn->Open("","","",adConnectUnspecified);
    pRst=pConn->Execute("select * from entrusts",NULL,adCmdText);
    应该是连接字符串不对,或者select 语句不对。