Solved

Timeout on cRecordset using a ODBC connection

Posted on 2011-02-10
3
931 Views
Last Modified: 2012-05-11
Hi,
I'm using a CRecordset object to connect to a SQL Server database through an ODBC connection.
However sometimes the query takes more than 15 seconds and the call to open times out.

// Loop that tries to obtain the result of a query.          
               try 
		{
			m_mydb.Open();
		}
		catch (CDBException* e )
		{
                     if (!maxretries)
                    {
				AfxMessageBox( e->m_strError,   
							  MB_ICONEXCLAMATION );
				e->Delete();
				//return NULL;
				exit(-1);
                  }
                  else
                  {
                      maxretries--;
                     // Give it one more chance
                     continue;
                  }
               }

Open in new window


Setting SetQueryTimeout(0) has absolutely no effect. I keep trying in my loop because sometimes I've just waited too little for my whole data set to be ready and on a new request I actually get the info.
 Anyone knows a more efficient way to do this ?

0
Comment
Question by:rjorge
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 34869715
you should do the connect before open by using a CDataBase object. then pass a pointer to that CDataBase when constructing the recordset. You can use the CDataBase pointer for whole session.

The SetQueryTimeout only has effect for timeout after a connect. so it works for example if you do a longer query in a stored procedure.

Sara
0
 

Author Comment

by:rjorge
ID: 34878141
Hi Sara,
I understand the advantage of having a unique connection object, and associating that to the 1 or more CRecordset objects I may have for the different queries. In terms of task separation, and keeping less connections it makes sense. But, apart from that, can you tell me whether that could benefit me performance wise?
0
 
LVL 33

Expert Comment

by:sarabande
ID: 34880838
if you have an open connection you could call the SetQueryTimeout to increase the timeout for longer queries. that could be a solution if the timeout comes because of a long and difficult query. if the reason of the timeout is unknown, you at least would know whether the connect or the query has the issue.

Sara
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question