每个线程连不同的库
线程开始和结尾前使用了
CoInitialize;
CoUninitialize;
m_pConnection也open了
但是m_pRecordset = m_pConnection->Execute(sqlcount,&RecordsAffected,adCmdText);
就得不到结果.不知道问题在什么地方?
是要设置什么参数吗?
HRESULT hr4 = m_pRecordset_class->Open("SELECT * FROM List_Keyword ORDER BY Length(keyword) DESC",_variant_t((IDispatch*)m_pConnection_class,true),adOpenStatic,adLockOptimistic,adCmdText);
就直接抛出异常
8 个解决方案
inline int GetDBCount(_ConnectionPtr m_pConnection,const char *db)
{
long num =0;
_RecordsetPtr m_pRecordset;
_variant_t RecordsAffected;
///执行SQL统计命令得到包含记录条数的记录集
char sqlcount[128]="SELECT COUNT(*) FROM ";
strcat(sqlcount,db);
m_pRecordset = m_pConnection->Execute(sqlcount,&RecordsAffected,adCmdText);
_variant_t vIndex = (long)0;
_variant_t vCount = m_pRecordset->GetCollect(vIndex);
m_pRecordset->Close();
num = vCount.lVal;
return num;
}这个函数也不好使了
封装的一个ADO类http://www.codetools.com/database/caaadoclass1.asp
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=39173
1.stdafx.h中加入
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
2。app文件的InitInstance中加入
if(S_OK!=OleInitialize(NULL))
{
AfxMessageBox("初始化COM组件库错误");
}
下面就是数据库操作
_ConnectionPtr pConn;
_RecordsetPtr pRs;
CString strSQL;
pConn.CreateInstance(__uuidof(Connection));
pConn->CursorLocation=adUseClient;
strSQL="Provider=SQLOLEDB;Server=Gooyan;DataBase=SkillsBox;UID=sa;PWD=aaaaaaaa";
pConn->Open(_bstr_t(strSQL),"","",-1);
pRs.CreateInstance(__uuidof(Recordset));
pRs->CursorLocation=adUseClient;
pRs->PutActiveConnection(pConn.GetInterfacePtr());
pRs1.CreateInstance(__uuidof(Recordset));
pRs1->CursorLocation=adUseClient;
pRs1->PutActiveConnection(pConn.GetInterfacePtr());
strSQL="select * from catalog order by cataid";
pRs->Open(_bstr_t(strSQL),vtMissing,adOpenDynamic,adLockBatchOptimistic,adCmdText);
每个线程里的数据库连接使用的如果是同一个用户名,那可能会有问题,oracle会限制
我每个线程连接的都是不同的数据库!访问冲突无从说起吧。