Click to See Complete Forum and Search --> : how to ever judge if the connection to database is avialable ?


suchuhui80
April 10th, 2007, 07:06 AM
I am using ADO to connection to oracle database ,the code below is for doing the judgement , but the expression return TRUE even I disable the network-connection through clicking the "diable" item in "local-connection" . Is there something wrong ? any other way ?


return (m_pConnection != NULL && (m_pConnection->State & adStateOpen));
// _ConnectionPtr m_pConnection .

suchuhui80
April 10th, 2007, 08:46 PM
please help .

wildfrog
April 10th, 2007, 09:06 PM
Usually you cannot determine whether a connection is alive or not before you actually try to use the connection. Even if your test would work, the connection might drop a split second after the test is performed... and you're really back to square one.

Communication protocols are often built in a way which allows them to stack ontop of each other. Like, SQL connections can run ontop of HTTP which in turn runs on TCP or UDP which may run on copper, fiber or even carried by pigeons. With all these 'levels' there's not always such thing as a connection.

- petter

aniskhan
April 11th, 2007, 02:03 AM
try thisreturn (m_pConnection != NULL && (m_pConnection->State == adStateOpen));

Shuja Ali
April 11th, 2007, 02:16 AM
Well there is no event that gets fired when the database server goes down or the network goes down. Checking the state of the connection won't tell you if the database server is down/network is down or not.

One work around would be to put a proper error handling routine in all of your methods that do any kind of database operations.

Remember ADO.NET would not know that your network is not working or the database server is down unless it tries to communicate with the server.

ovidiucucu
April 21st, 2007, 02:51 AM
[ Merged threads ]