Asp tutorial. net connecting to oracle
<Add key = "connectionstring" value = "data source = orcl; user id = xxx; password = xxx"/>
The code in the button is as follows:
String constr = system. configuration. configurationmanager. apps tutorial ettings ["connectionstring"]. tostring ();
Oracleconnection conn = new oracleconnection (constr );
Conn. open ();
See c # connection below
First install the oracle client
1. Control Panel-> Administrative Tools-> data source (odbc)-> Add data source-> Select oracle client
Data source name can be any name. We recommend that you use the same name as sid.
Description
The tns service name drop-down menu automatically displays the service_name name in the tnsnames. ora file under the Directory specified by the environment variable tns_admin, that is, the sid userid to be connected.
2. Code
String connectionstring = "data source = orcl; user id = scott; password = scott"; // connection string
Oracleconnection conn = new oracleconnection (connectionstring); // create a new connection
Try
{
Conn. open (); // open the connection
Oraclecommand cmd = conn. createcommand ();
Cmd. commandtext = "select * from emp"; // SQL statement
Oracledatareader rs = cmd.exe cutereader ();
While (rs. read () // read data. If rs. read () returns false, it indicates the end of the record set.
{
Messagebox. show (rs. getstring (1 ));
}
Rs. close ();
}
Catch (exception e)
{
Messagebox. show (e. message );
}
Finally
{
Conn. close ();
}