Connection Timeout in ADO does not work!
Posted on 2003-02-22
Ok, guys, here is a question that I really need answered. Who ever can help me with this one will receiving a whooping 280 points.
I have wrote a program in C++ using ADO, where I connect to SQL Server using ODBC, execute a stored procedure and then get the results. The program is compiled as DLL and is used on W2K machine.
The problem that I noticed is that ConnectionTimeout and CommandTimeout properties do not have an efect on the connection timeout. For example, I have SQL server running on the remote machine and so, I unplug that machine from the network. Then, I start my program, and guess what -^ the timeout value for the connection.open request is always somewhere between 45 secs ad 2 minutes.
I am using MDAC 2.6 (and cannot upgrade).
What I need help with:
1. Be able to set the timeout value for the connection.open in ADO
2. be able to set the timeout value for the command.Execute in ADO
Here is the sample of the code where I do it:
HRESULT hr = m_pConn.CreateInstance (__uuidof (Connection));
if (FAILED (hr))
m_pConn->ConnectionTimeout = 10; // set timeout to 10 seconds
if (FAILED (m_pConn->Open (_bstr_t (m_connect_str),
_bstr_t (""), _bstr_t (""), adConnectUnspecified)))
// and later on in the code:
hr = pCommand.CreateInstance (__uuidof (Command));
if (FAILED (hr))
pCommand->ActiveConnection = m_pConn;
pConnand->CommandTimeout = 10;
pCommand->CommandText = (_bstr_t)m_SQL;
pCommand->CommandType = adCmdStoredProc; // this is a stored procedure
// and later on in the code
pCommand->Execute(NULL, NULL, adCmdStoredProc);
I was able to get the timeout to work in VB, but not in VC. Please help me to get it to work!