Question Test if database connection is open

Bernie

Well-known member
Joined
Aug 13, 2007
Messages
98
Programming Experience
3-5
How can I test a database connection if it's open. The application is cleaning up after a try/catch block. If I put the connection.close in the try block, an error before that line will leave the connection open. If I put it in the finally block, then an error opening the connection in try block will cause the connection to be close and the connection.close in the finally will errror.

How can I do something like;

if connection.isopen then
do something
endif

Thanks,
Bernie
 
Bingo!

If Not cnConnection.State = ConnectionState.Closed Then
cnConnection.Close()
End If

Thanks,
Bernie
 
Back
Top