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