Asp.net and c # connect to Oracle through oledb

Source: Internet
Author: User

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

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.