Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# oracle : catch all exceptions relative to connectivity?

In c#, can I catch all errors about (non) connectivity to an Oracle database?

I don't want to catch error about badly written query but only errors like No listener, connection lost...

If queries are badly written (or table are missing) then this is my fault. But if Oracle or the network is down then this should be held by another department.

like image 382
frenchone Avatar asked Sep 18 '25 02:09

frenchone


2 Answers

Write your code in which you build the connection in a try catch part:

try
{
   BuildConnection(connectionString);
}
catch (OracleException ex)
{
   //Connectivity Error
}
like image 121
CloudyMarble Avatar answered Sep 20 '25 16:09

CloudyMarble


Errors between ORA-12150 to ORA-12236 are related to connection errors. A few examples:

ORA-12154: TNS:could not resolve the connect identifier specified

ORA-12152: TNS:unable to send break message

ORA-12157: TNS:internal network communication error

Please refer to https://docs.oracle.com/cd/E11882_01/server.112/e17766/net12150.htm

like image 43
ozanmut Avatar answered Sep 20 '25 16:09

ozanmut