ado 的小问题,谁遇到过?
不知道为什么,在第一次使用rec->open(......)的时候会抛出异常,此异常似乎跟数据库连接有关系,在第二次的时候就没问题呢?我调了无数遍终于发现这个问题,就是没法解决,大家快帮帮我。
CString source("Driver={SQL SERVER};Server=test;Database=TestDB;UID=tt;PWD=tt");
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open(_bstr_t(source),"","",16);
_RecordsetPtr rec;
rec.CreateInstance(__uuidof(Recordset));
CString strQuery;
strQuery.Format("select * from testTB");
try
{
rec->Open(_bstr_t(strQuery),m_pConnection.GetInterfacePtr() ,adOpenDynamic,adLockOptimistic,adCmdText); //此句出错:unknown error 0x800a0e81
}
catch(_com_error&e)
{
AfxMessageBox(e.ErrorMessage());
}
_RecordsetPtr rec2;
rec2.CreateInstance(__uuidof(Recordset));
try
{
rec2->Open(_bstr_t(strQuery),m_pConnection.GetInterfacePtr() ,adOpenDynamic,adLockOptimistic,adCmdText); //没有任何错误
}
catch(_com_error&e)
{
AfxMessageBox(e.ErrorMessage());
}