Solved

Timeout on cRecordset using a ODBC connection

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 56
Is there any Easy way to copy CSV to SQL Server using C# 3 69
max float value 3 25
Sql query 107 25
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…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

912 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

16 Experts available now in Live!

Get 1:1 Help Now