Gold
Gold

Reputation: 62424

Open Connection to database, How to check if still existing?

I open connection to database in the biginig of my program (one time)

after 5 minute the server shut down.

how I can catch this problem ?

I am not open connection befor any query

thank's

Upvotes: 0

Views: 644

Answers (2)

Marcom
Marcom

Reputation: 4741

In general you shouldnt keep you connection open. But if the connection has been open for some time its always prudent to check if the conneciton is still active.

Sqlconnection has a connection state property, and also catch sqlexceptions so you know that the problem is db related.

Upvotes: 0

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68667

In general you shouldn't keep the connection open, but keep the connection in the pool. If the connection is broken, any command you try to execute on it will throw an exception and you can handle the problem and attempt to reconnect.

Upvotes: 2

Related Questions