新手求教 为什么连接SqlServer报错?
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
// 打开本地Access库Demo.mdb
m_pConnection->Open("Provider=SQLOLEDB.1;Data Source=127.0.0.1;Initial Catalog=simple;UID=sa;Integrated Security=SSPI","","",adModeUnknown);
}
catch(_com_error e)
{
MessageBox(NULL,NULL,"数据库连接失败,确认数据库是否在当前路径下!",MB_OK);
// return FALSE;
}
// ---------------------------------------------------------------------------------------------------
CString str= "SELECT * FROM mytable ";
// 使用ADO创建数据库记录集
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open((LPCTSTR)str, //到这个函数报错了
m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}