Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2008
How to verify opened database connections?


Message 1 in thread

I've created connection pool mechanism to maintain the opened database
connections and a procedure to use/release connections, some time connection
pool might hold bad connections due to db or network issues or some other
reasons, so I need to remove such bad connections from the pool and to do
that I am trying to add cleanup code to be executed at regular interval.

Question here is: What is the best method to determine the bad connection in
the pool?

I would like to do without executing a SQL query, is there a quick method to
verify the db connection using the connection object?
If not what is the correct/best method to verify the opened connections
(without affecting the application performance)?

Thanks,
Bab

Message 2 in thread

On torsdag den 3. Januar 2008, Babu Sathyanarayana wrote:
> I've created connection pool mechanism to maintain the opened database
> connections and a procedure to use/release connections, some time
> connection pool might hold bad connections due to db or network issues or
> some other reasons, so I need to remove such bad connections from the pool
> and to do that I am trying to add cleanup code to be executed at regular
> interval.
>
> Question here is: What is the best method to determine the bad connection
> in the pool?
>
> I would like to do without executing a SQL query, is there a quick method
> to verify the db connection using the connection object?
> If not what is the correct/best method to verify the opened connections
> (without affecting the application performance)?

I don't think there is a way to do it without running an SQL query. There 
might be driver specific ways to do it for some of the drivers, but I would 
stay clear of those.

You could make a stored procedure called ping that returns an empty result 
set. That shouldn't affect performance in any way. But that's still a ping, 
not a signal you get.

The correct approach would be to make your queries robust and automatically 
try reconnecting after loosing the connection. Even if you did get a signal 
on connection lost, you will have race conditions between these and executing 
queries.

Bo.

-- 
 [ signature omitted ]