VC++,ADO 同时打开同一个access数据库的两张表时出现异常

VC++,ADO 同时打开同一个access数据库的两张表时出现错误

[code=C/C++][/code]
// TODO: Add extra validation here
UpdateData(TRUE);
if ((m_readernumber.IsEmpty()) || (m_booknumber).IsEmpty())
{
MessageBox("读者编号或图书编号不能为空!");
}
//中间变量
int nCanborrow;

_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset1,m_pRecordset2;
//初始化指针
m_pConnection.CreateInstance("ADODB.Connection");
//连接数据库
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=my.mdb","","",adModeUnknown);
  //初始化记录1指针
m_pRecordset1.CreateInstance(__uuidof(Recordset));
  //打开记录集
CString strSql1 = "select ReaderName,CanBorrow from Reader where ReaderId = '"+m_readernumber+"' ";
BSTR bstrSQL1 = strSql1.AllocSysString(); 
m_pRecordset1->Open(bstrSQL1,(IDispatch*)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
   
//遍历所有记录
while(!m_pRecordset1->adoEOF)

//取纪录字段值
_variant_t TheValue; //VARIANT数据类型,中间变量
TheValue = m_pRecordset1->GetCollect("ReaderName");
if(TheValue.vt != VT_NULL)
m_readername = (LPCSTR)_bstr_t(TheValue);

TheValue = m_pRecordset1->GetCollect("CanBorrow");
if(TheValue.vt != VT_NULL)
nCanborrow = atoi((LPCSTR)_bstr_t(TheValue));//转换为int
  //移动到下一记录
m_pRecordset1->MoveNext();
}
m_pRecordset1->Close(); 

m_pRecordset1 = NULL;

if (nCanborrow == 0)
{
MessageBox("不能借!","提示");
return;
}


CString strCanlendout;
  //初始化记录2指针
m_pRecordset2.CreateInstance(__uuidof(Recordset));
  //打开记录集
CString strSql2 = "select CanLendOut from Book where ReaderId = '"+m_booknumber+"' ";
BSTR bstrSQL2 = strSql2.AllocSysString(); ////////////////////////////////////////////////////////
m_pRecordset2->Open(bstrSQL2,(IDispatch*)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
   
//遍历记录
while(!m_pRecordset2->adoEOF)
{
_variant_t TheValue;
TheValue = m_pRecordset2->GetCollect("CanLendOut");
if (TheValue.vt != VT_NULL)
strCanlendout = (LPCSTR)_bstr_t(TheValue);
//移动记录
m_pRecordset2->MoveNext();
}
  m_pRecordset2->Close();
m_pRecordset2 = NULL;

if (strCanlendout == "0")
{
MessageBox("不可外借!","提示");
return;
}

//执行操作


上面就是一个按钮的消息函数。要实现打开第一个表,读出数据,然后再打开第二个表,读出数据。
在屏蔽打开第二个表的操作代码时候可以运行,但是一打开第二个表就出错。
是怎么回事呢?
刚刚来这个论坛,只有这么点分。

------解决方案--------------------
用try...catch定位错误。
打开第二个表的sql语句,在数据库上是否能正常执行?
------解决方案--------------------
看不到出来,不过AllocSysString获得的BSTR,应该::SysFreeString 进行释放