HRESULT hr = S_OK;
_bstr_t strConnection("Driver={SQL Server};SERVER=YUP;DATABASE=Maindb;UID=test;PWD=test");
_bstr_t user("");
_bstr_t pwd("");
_bstr_t strSql("Select * From GroupTable"); hr = m_connection.CreateInstance( _uuidof(Connection) );
hr = m_connection->Open(strConnection,user,pwd,16);
hr = m_recordset.CreateInstance( _uuidof(Recordset) );
try
{
hr = m_recordset->Open( strSql, 
strConnection, 
adOpenDynamic, 
adLockOptimistic, 
adCmdText );
}
catch(_com_error &e)
{
MessageBox(e.ErrorMessage());
}

解决方案 »

  1.   

    hr = m_recordset->Open( strSql, 
    m_connection.GetInterfacePtr(), 
    adOpenDynamic, 
    adLockOptimistic, 
    adCmdText );
      

  2.   

    hr = m_recordset->Open( strSql, 
    m_connection.GetInterfacePtr(), 
    adOpenDynamic, 
    adLockOptimistic, 
    adCmdText );
      

  3.   

    hr = m_connection->Open(strConnection,user,pwd,-1);
      

  4.   

    你把SQL SERVER中的SERVER 的authentication 设置成SQL Server and Windows 就可以了!我和你出的问题一样。