::CoInitialize(NULL);
hr=theApp.m_pConnect.CreateInstance(__uuidof(Connection));
_bstr_t source("Driver={SQL Server};Server=qiudong;Uid=sa;Pwd=;Database=test");
_bstr_t user("sa");
_bstr_t pwd("");
if(SUCCEEDED(hr))
{
hr=theApp.m_pConnect->Open(source,user,pwd,16);
}
m_pRecordset.CreateInstance(__uuidof(Recordset));
// sprintf(buf,"select * from user where user_name=\'%s\' and user_password=\'%s\'",m_strUsername,m_strPassword);
CString strSQL;
strSQL="select * from user where user_name=qqqq and user_password=1111";
_bstr_t bstrSQL = strSQL.AllocSysString();
m_pRecordset->Open(bstrSQL,theApp.m_pConnect.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
AfxMessageBox("用户名或密码不符合");
m_strUsername="";
m_strPassword="";
UpdateData(FALSE);
return;
}
m_pRecordset->Close();
运行到m_pRecordset->Open...出现未知错误!请教各位我错哪了????

解决方案 »

  1.   


    你的theApp.m_pConnect.GetInterfacePtr()环城",(IDispatch*)m_pConnection试试看
      

  2.   

    select * from user where user_name='qqqq' and user_password='1111';
    是varchar字段吧哈?
      

  3.   

    1: 用try...catch捕获错误有助于发现问题。
    2: user_name=qqqq qqqq应加'', llll 同样。
      

  4.   

    我用了try..catch
    反回的是unkownn error 0x800A0E81
      

  5.   

    m_pRecordset.CreateInstance(__uuidof(Recordset));
    初始化都很正常,就是Open就出错!?请各位帮帮忙!!
      

  6.   

    theApp.m_pConnect->Open (source,"","",-1);
      

  7.   

    用ERR LOOKUP 查一下是什么错,再解决。