Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
I want to test the Oracle and SQL servers running are Up or Down. Currently, I am using the following way to check the connection.. for example Oracle connection as ..
Dim cn As OracleConnection
cn = New OracleConnection(ConnStr)
cn.Open() 

This is working fine. But, is there any other way to check the DB up status like Ping.
Please suggest.
Posted
Updated 12-Feb-11 4:26am
v2

You could do a mix of pinging the server IP and also doing a TCP connection to the server port (to see if it's open). But while that would establish that the machine is up and accessible over the network, and that the database server is listening on the expected ports, it does not guarantee that the database is in a stable condition, for that you do need to actually try establishing a database connection as you are doing above.
 
Share this answer
 
v2
Comments
Sreenath Gv 12-Feb-11 10:04am    
Hi, Nishanth thanks a lot. But, if connection fails, it thows error..and I am handling it..but not sure when it will crash right. Any idea..!
Nish Nishant 12-Feb-11 10:04am    
It's Nishant please (no h) :-)

And what do you mean by "crash"? Your app or the DB server?
Sreenath Gv 12-Feb-11 10:12am    
No I mean, browser may freez due to continuous exceptions..!
Nish Nishant 12-Feb-11 10:27am    
Well the ping code will be running on the backend, so it should not affect the browser.
Sreenath Gv 12-Feb-11 10:09am    
it alwasy throws error if connection fails. In this way, I am looping some 10 to 15 Oracle and SQL servers..and if most of them are down then it will throw execption many times. That was the reason why I am trying to get some other way actually.
Any idea on this.
You are in the right direction. You can check for the connection state as well

VB
Dim cn As OracleConnection
cn = New OracleConnection(ConnStr)
cn.Open()
If (cn.State And ConnectionState.Open) > 0 Then
    'Do whatever you want
    cn.Close()
Else
    'Oops, it an't open
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900