帮忙看看下面这段代码,出错处理我省了
STDMETHODIMP CTest::GetInfo(BSTR *Info)
{
// TODO: Add your implementation code here
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("Provider=SQLOLEDB;SERVER=(local);DATABASE=exam;UID=sa;PWD=linchun","","",-1); CComBSTR m_bstrSQL;
m_bstrSQL.Append("select * from single where Qid<>0");
_bstr_t m_strResult(m_bstrSQL,FALSE);
CComVariant m_varNum; _RecordsetPtr m_pRs;
m_pRs=m_pConnection->Execute(m_strResult,&m_varNum,-1); CComVariant m_varData;
CComBSTR m_bstrInfo;
while(!m_pRs->ADOEOF)
{

m_pRs->GetFields()->GetItem("content")->get_Value(&m_varData);
m_bstrInfo.AppendBSTR(m_varData.bstrVal);
m_pRs->MoveNext();
} m_pRs->Close();
m_pConnection->Close();
*Info=m_bstrInfo;
return S_OK;
}
这段代码没问题,客户端调用也完全正常,
问题在这句
m_bstrSQL.Append("select * from single where Qid<>0");
我库中本来就没有Qid=0的数据,所以这句也就相当于
m_bstrSQL.Append("select * from single");
但这样编译成生dll是没问题,但在客户端调用就出现异常,为什么呢?
还有m_pRs->Close();后,还需要释放吗?