I am looking to write a C# class to run at regular intervals that check if an oracle database is available/online/can be connected to. I am wondering what is the be开发者_如何学编程st way to achieve this? How can i check if an oracle database is available?
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson01.aspx
Basically, you periodically open a connection to your database (and then close it). If it doesn't throw an exception, the database is available (although it may have other issues that aren't apparent from a simple connection).
As MusiGenesis said you can open and close a connection and check for the error conditions but also be sure to make a simple query like "select 1 from dual;" and check for the result because with a simple connection you may not get some of the low level errors like "ORA-01507 : Database not mounted" or "ORA-01034 : Oracle not available".
精彩评论