Solved

Timeout on cRecordset using a ODBC connection

Posted on 2011-02-10
3
897 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 32

Accepted Solution

by:
sarabande earned 500 total points
Comment Utility
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
Comment Utility
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 32

Expert Comment

by:sarabande
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now