C # connecting to a remote oracle database

Source: Internet
Author: User
Tags oracleconnection
There are two main methods: one is to directly write the connection string, and the other is to download the connection string to the web. in the config file, the following are the instructions for writing the connection string: privatestaticstringconnstrDataSource (DESCRIPTION (ADDRESS_LIST (ADDRESS (PROTOCOLTCP) (how.host) (PORTmport)

There are two main methods: one is to directly write the connection string, and the other is to download the connection string to the web. in the config file, the following are the instructions for writing the connection string: private static string connstr = "Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = Mhost) (PORT = mport

There are two main methods: one is to directly write the connection string, and the other is to download the connection string to the web. config file, which are described below:
Directly write the connection string:

 private static string connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Mhost) (PORT=mport)))(CONNECT_DATA=(SERVICE_NAME=mywervicename)));Persist Security Info=True;User Id=myusername; Password=mypassword"; private OracleConnection DBCONN = new OracleConnection(connstr);

Write the connection string in the web. config file.

private static string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;private OracleConnection DBCONN = new OracleConnection(connstr);

In this way, add the following configuration information to the configuration file.

Then you can open the connection and query the data.
As shown below:

  public void GetData()        {            if (DBCONN.State == ConnectionState.Closed)            {                DBCONN.Open();                string quarystr = "select * from tablename";                OracleCommand comm = new OracleCommand(quarystr, DBCONN);                OracleDataReader reader;                reader = comm.ExecuteReader();                while (reader.Read())                {                    string str = "" + reader.GetString(1);                }            }        }

Reprinted, please note: blog of past days» c # connect to a remote oracle database

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.