ADODB::_RecordsetPtr::Open throws Exception like Query timeout Expired in c++

假装没事ソ 提交于 2019-12-13 18:08:36

问题


here i am trying to query a table of sql server 2008 r2 from my c++ application. It contains 21,54,514. but it throws an exception like "Query timeout expired" . below is my code base

ADODB::_ConnectionPtr           m_pDBConnection;
ADODB::_RecordsetPtr                m_pRS;

m_pDBConnection.CreateInstance("ADODB.Connection");
m_pRS.CreateInstance("ADODB.RecordSet");

m_pRS->Open(wstrSQL.c_str(), _variant_t((IDispatch *) m_pDBConnection, true),
        ADODB::adOpenStatic,
        ADODB::adLockReadOnly,
        ADODB::adCmdText);

When the above line is get executed it throws the above said exception.

i know the issue , the issue is actually with default timeout set. it is actually 15 sec.

can anybody please tell how to reset or change timeout in ADODB::_RecordsetPtr. I searched in google a lot , we can do reset timeout for ADODB::_ConnectionPtr but not for ADODB::_RecordsetPtr. it would be vary usefull for me. Thanks in advance.


回答1:


According to Coding Journey you need to set the CommandTimeout on the connection and on the command.

// The recordset for the result
ADODB::_RecordsetPtr rs;
// Timeout on connection
m_pDBConnection->CommandTimeout = 60;
// Need to create command first, then configure it, then open RecordSet
ADODB::_CommandPtr cmd(__uuidof(ADODB::Command));
cmd->ActiveConnection = m_pDBConnection;
cmd->CommandText = wstrSQL.c_str();
cmd->CommandTimeout = 60;
rs->Open(cmd, vtMissing, ADODB::adOpenStatic, ADODB::adLockReadOnly, ADODB::adCmdText);
// Reset the timeout on the connection
m_pDBConnection->CommandTimeout = 15;


来源:https://stackoverflow.com/questions/24508564/adodb-recordsetptropen-throws-exception-like-query-timeout-expired-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!