?
Solved

Timeout on cRecordset using a ODBC connection

Posted on 2011-02-10
3
Medium Priority
?
1,000 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 35

Accepted Solution

by:
sarabande earned 2000 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 35

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to clear a vector as well as how to detect empty vectors in C++.

752 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