C # remote connection to the ORACLE database,

Source: Internet
Author: User
Tags oracleconnection

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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.