Ado. NET Connect Oracle

Source: Internet
Author: User
Tags oracleconnection

1. Add Oracle.ManagedDataAccess.dll

2. The instance connecting Oracle is added to the Oracle listener, or the error "Ora-12514:tns: The listener is currently unable to identify the service requested in the connection descriptor " is added as follows, this example uses oracle10g to find the \ c Oracle\product\10.2.0\db_1\network\admin under Lisener.org, change the section after opening to add red

# Listener.ora Network Configuration file:c:\oracle\product\10.2.0\db_1\network\admin\listener.ora# Generated by Oracle configuration Tools. Sid_list_listener =  (sid_list = (    Sid_desc =      (sid_name = Plsextproc)      (oracle_home = C:\oracle\product\ 10.2.0\db_1) (Program      = extproc)    )    (Sid_desc =      (global_dbname = ORCL)      (oracle_home = c \ oracle\product\10.2.0\db_1)      (sid_name = ORCL)    )  ) LISTENER =  (description_list =    ( DESCRIPTION =      (address = (PROTOCOL = IPC) (KEY = EXTPROC1))      (address = (PROTOCOL = TCP) (HOST = 192.168.121.130) (P ORT = 1521))))  

3. Connection string:

String connstr = "Data source= (description= (address= (protocol=tcp) (host=192.168.121.130) (port=1521)) (CONNECT_DATA= (SERVICE_NAME=ORCL))); Persist Security info=true; User Id=scott; Password=tiger; ";

where Oracle database server ip:192.168.121.130

Servicename:orcl

User name: Scott

Password: Tiger

4. View the instance name of Oracle, log in with SYS as DBA, execute the statement select name from V$database;

5,c# Code

Using system;using system.collections.generic;using system.configuration;using Oracle.ManagedDataAccess.Client;        Using system.linq;using System.text;namespace adosample{class Program {static void Main (string[] args) {String connstr = "Data source=" (Description= (address= (protocol=tcp) (host=192.168.121.130) (port=15 )) (Connect_data= (SERVICE_NAME=ORCL))); Persist Security info=true; User Id=scott;            Password=tiger; ";  using (OracleConnection conn = new OracleConnection (connstr)) {String sql = "SELECT * FROM Dept                "; Conn.                Open (); using (oraclecommand cmd = new OracleCommand (SQL, conn)) {using (OracleDataReader Datar Eader = cmd.                            ExecuteReader ()) {while (Datareader.read ()) {                            String obj = (string) datareader[1];       Console.WriteLine (obj);                 }}}} Console.readkey (); }    }}

  

Ado. NET Connect Oracle

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.