I am doing that now. I think the code snippet, which I have mentioned was failing to detect strictly whether the DB is up or not because the connection object is pooled. I want to know if there is any better way of achieving the same ?
If you look at my code, I am doing the same, but what's happening is even if I disconnect the cable, the _con.Open executes without any error and the connection State also shows OPEN. I added one additional step where I am querying something from table,
this steps ensures if the DB is up or not. Don't think this soln is elegant but till I get a better soln, I will go with that approach.
pure_m23
Member
14 Points
5 Posts
Need to check whether DB is up or not.
Jan 24, 2012 06:38 AM|LINK
Database _db = DatabaseFactory.CreateDatabase("Connection Config Key"); System.Data.Common.DbConnection _conn; do { try { _conn = _db.CreateConnection(); _conn.Open(); _conn.Close(); _conn.Dispose(); break;//Connection is established } catch(Exception) { //No Connection... retry } }while(true);Rab Nawaz Kh...
Participant
923 Points
198 Posts
Re: Need to check whether DB is up or not.
Jan 24, 2012 06:55 AM|LINK
please visit the below URL, it may solve your problem
http://stackoverflow.com/questions/927567/in-c-sharp-what-is-the-best-way-to-determine-if-a-database-is-up-and-running
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Need to check whether DB is up or not.
Jan 24, 2012 06:55 AM|LINK
read at least a table.
pure_m23
Member
14 Points
5 Posts
Re: Need to check whether DB is up or not.
Jan 25, 2012 06:31 AM|LINK
I am doing that now. I think the code snippet, which I have mentioned was failing to detect strictly whether the DB is up or not because the connection object is pooled. I want to know if there is any better way of achieving the same ?
Regards,
M
pure_m23
Member
14 Points
5 Posts
Re: Need to check whether DB is up or not.
Jan 25, 2012 06:46 AM|LINK
HI Khan,
If you look at my code, I am doing the same, but what's happening is even if I disconnect the cable, the _con.Open executes without any error and the connection State also shows OPEN. I added one additional step where I am querying something from table, this steps ensures if the DB is up or not. Don't think this soln is elegant but till I get a better soln, I will go with that approach.
Regards,
M