ADODB :: _ RecordsetPtr :: Open引发异常,例如查询超时在c ++中过期 [英] ADODB::_RecordsetPtr::Open throws Exception like Query timeout Expired in c++
问题描述
在这里,我尝试从我的C ++应用程序查询sql server 2008 r2的表。它包含21,54,514。但它会引发类似查询超时已过期之类的异常。下面是我的代码
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.
我知道这个问题,实际上是默认超时设置了。实际上是15秒。
i know the issue , the issue is actually with default timeout set. it is actually 15 sec.
任何人都可以在 ADODB :: _ RecordsetPtr 中告诉如何重设或更改超时。我在Google上进行了大量搜索,我们可以为 ADODB :: _ ConnectionPtr 重置超时,但不能为 ADODB :: _ RecordsetPtr 重置超时。对我来说将是非常有用的。
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.
推荐答案
根据编码之旅,您需要设置 CommandTimeout (位于连接和上)。
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;
这篇关于ADODB :: _ RecordsetPtr :: Open引发异常,例如查询超时在c ++中过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!