user9658871
user9658871

Reputation:

How to set or disable the Query Timeout with a C++'s CDatabase ODBC connection to a SQL Server database

I need to have a query run by some code. Running the query in MSSMS takes a minute and a half (not too shabby for over 4M rows). In code I open the connection with

CDatabase *base = new CDatabase () ;
base->OpenEx ("Driver={SQL Server};Server=Computer\\User;Database=base;") ;

I can then create CRecordset objects and run queries. The SELECT COUNT query works properly (gives ~4M). The first SELECT cols query (fetching some attributes) works properly. Their respective CRecordset are properly closed and cleaned. The second SELECT cols query (big join that returns the 4M rows) times out on every try.

I do not know how to set up the query timeout value, how that parameter would be called, or where to set it in the first place. I tried many combinations of parameters in the connection string, I tried editing the ODBC pilot pooling options. I am not interested in using another ODBC connection object, but I can set up a DSN and connect through it instead of using the direct connection string.

Worst comes to worst I'll just paginate it all but right now it's a hassle, and since the query can timeout, logically there should be a way to set that timeout too, I'd like to know what it is.

Upvotes: 0

Views: 1235

Answers (1)

AlwaysLearning
AlwaysLearning

Reputation: 8819

Query timeout is not a connection string parameter, at least not for SQL Server. You're probably looking for the CDatabase::SetQueryTimeout member function.

Upvotes: 0

Related Questions