用ADO连接SqlServer2000,程序运行的时候捕捉到异常:
Error:-2147217887Msg:IDispatch error #3105Description多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成请问导致这个原因是什么??
在网上找了不少答案,MSDN上说的我也找做了。但是还是运行出错。在此贴出代码。望不吝赐教。
小弟在此先行谢过了。BOOL CInfo::OnInitDialog()
{
// TODO:  在此添加额外的初始化    CDialog::OnInitDialog();
::CoInitialize(NULL);
    
m_list.ResetContent();
    
selected="select * from [User]";
try
{
_variant_t var;
var=_variant_t(selected);
CString str_ip,str_username,str_groups,str_tc,str_description;
      
if (FAILED(pRS.CreateInstance(__uuidof(Recordset))))
        { 
            AfxMessageBox("不能打开记录集",MB_OK|MB_ICONEXCLAMATION,0);
            return FALSE;
         }

if(FAILED(pRS->Open(var,_bstr_t(path),adOpenStatic,adLockOptimistic,adCmdText)))
        {//path = "Driver=SQL Server;Server=PC-201004121940;Database=LIZHUO;Integrated Security=True";
AfxMessageBox("Open table failed!");
            pRS.Release();
            return FALSE;
}
        
if(!pRS->BOF)
pRS->MoveFirst();
else
{
AfxMessageBox("数据表为空!~");
} while(!pRS->adoEOF)
{
var=pRS->GetCollect("ip");
if(var.vt!=VT_NULL)
str_ip=(LPCSTR)_bstr_t(var);
var=pRS->GetCollect("username");
            if(var.vt!=VT_NULL)
str_username=(LPCSTR)_bstr_t(var);
            var=pRS->GetCollect("groups");
if(var.vt!=VT_NULL)
str_groups=(LPCSTR)_bstr_t(var);
var=pRS->GetCollect("tc");
            if(var.vt!=VT_NULL)
str_tc=(LPCSTR)_bstr_t(var);
            var=pRS->GetCollect("groups_description");
            if(var.vt!=VT_NULL)
str_description=(LPCSTR)_bstr_t(var);
m_list.AddString(str_ip+"->"+str_username+"->"
+str_groups+"->"+str_tc+"->"+str_description);
pRS->MoveNext();
}
}
catch(_com_error &e)
{
        _bstr_t bstrSource(e.Source());
_bstr_t bs=_bstr_t("Error:")+_bstr_t(e.Error())+_bstr_t("Msg:")
+_bstr_t(e.ErrorMessage())+_bstr_t("Description")+_bstr_t(e.Description()); MessageBox(bs,bstrSource); }

return TRUE;  // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}

解决方案 »

  1.   


    BOOL CInfo::OnInitDialog()
    {
       selected="select * from [User]";
       try
        {
            _variant_t var;
            var=_variant_t(selected);
            CString str_ip,str_username,str_groups,str_tc,str_description;
         
            if (FAILED(pRS.CreateInstance(__uuidof(Recordset))))
            { 
                AfxMessageBox("不能打开记录集",MB_OK|MB_ICONEXCLAMATION,0);
                return FALSE;
             }
      
            if(FAILED(pRS->Open(var,_bstr_t(path),adOpenStatic,adLockOptimistic,adCmdText)))
            {//path = "Driver=SQL Server;Server=PC-201004121940;Database=LIZHUO;Integrated Security=True";
    //感觉pRS->Open()运行有问题,因为断点到这的时候就抛出异常,底下的语句都没运行
                AfxMessageBox("Open table failed!");
                pRS.Release();
                return FALSE;
            }
    /**/
        }
        catch(_com_error &e)
        {
            _bstr_t bstrSource(e.Source());
            _bstr_t bs=_bstr_t("Error:")+_bstr_t(e.Error())+_bstr_t("Msg:")
                +_bstr_t(e.ErrorMessage())+_bstr_t("Description")+_bstr_t(e.Description());        MessageBox(bs,bstrSource);    }    
        
        return TRUE;  // return TRUE unless you set the focus to a control
        // 异常: OCX 属性页应返回 FALSE
    }
      

  2.   

    找到解决办法了。看了这位大侠的文章,茅厕顿开
    http://blog.csdn.net/zyq5945/archive/2010/05/13/5586423.aspx
      

  3.   

    http://www.vckbase.com/document/viewdoc/?id=307
      

  4.   

    你有没有CoInitialize();或者有没进行com/ole初始化!