数据库重复打开出现ERROR
请教各位专家,当我执行下面语句的时候,会出现ERROR的现象呢??我用断点检查,执行到红色代码的地方就出现ERROR了,请问怎样解决呢?
_RecordsetPtr p1;
if (FAILED(p1.CreateInstance("ADODB.Recordset")))
{
AfxMessageBox("Create Instance failed!");
return;
}
CString c1;
c1.Format("select top 1 exam_room from baoming where exam_room is not null order by exam_room DESC");
if (FAILED(p1->Open((_variant_t)c1,(_variant_t)strSRC,adOpenStatic,adLockOptimistic,adCmdText)))
{
AfxMessageBox("Can not open Database!");
p1.Release();
return;
}
_RecordsetPtr p2;
if (FAILED(p2.CreateInstance("ADODB.Recordset")))
{
AfxMessageBox("Create Instance failed!");
return;
}
CString c2;
c2.Format( "select top 1 exam_seat from baoming where exam_room = (select top 1 exam_room from 16baoming where exam_room is not null order by exam_room DESC) order by exam_seat DESC");
if (FAILED(p2->Open((_variant_t)c2,(_variant_t)strSRC,adOpenStatic,adLockOptimistic,adCmdText)))
{
AfxMessageBox("Can not open Database!");
p2.Release();
return;
}