C # remote connection to the ORACLE database,
To use this method, you only need to input several necessary parameters to test the remote connection of the database. If the connection is successful, TRUE is returned, and false is returned if the connection fails. Note: The first parameter indicates the user in the database, and the second parameter indicates the user's password, the third parameter is not encrypted. It indicates the address of the login server. The fourth parameter indicates the port number of the login server. The fifth parameter indicates the name of the login database. Remember to reference the required parameter. // <summary>
/// Test Database Connectivity
/// </Summary>
Public static bool db_connection_test (string str_uid, string str_pwd, string str_serveraddr, string str_port, string str_dbname, ref string strErr)
{
String str_conn = string. format ("user id = {0}; password = {1}; data source = (DESCRIPTION = (ADDRESS = (PROTOCOL = tcp) (HOST = {2 }) (PORT = {3}) (CONNECT_DATA = (SERVICE_NAME = {4}) ", str_uid, str_pwd, str_serveraddr, str_port, str_dbname ); format the connection string OracleConnection Conn = new OracleConnection (str_conn); Define the connection instance
Try
{
Conn. Open (); Open the connection through the built-in method to test the connection to the instance
Conn. Close ();
Return true;
}
Catch (Exception ex)
{
StrErr = ex. Message;
Return false;
}
}