Solved

Timeout on cRecordset using a ODBC connection

Posted on 2011-02-10
3
956 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

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 34

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2015 Redefinition errors 4 91
What Is an Error? 2 27
Database Mail Profiles 1 22
calculate running total 8 14
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

733 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