How to connect to an Oracle database without the Oracle client installed in C #

Source: Internet
Author: User
Tags oracleconnection

Brief introduction:

It is also quite common that we often encounter the need to connect to an Oracle database when we develop our application scenarios. So so. NET environment is connected to an Oracle database and can be tns/sql.net through a configuration file, and TNS must be an Oracle client.
Scenario one, many are running on a server that does not have an Oracle client installed when using Microsoft's own using System.Data.OracleClient, which is said to be now not maintained, will prompt you to install the Oracle client. However, this approach is rarely used in versions beyond Oracle 12.
Scene Two, there are also many people directly invoke the Oracle client under the Oracle.DataAccess.dll(typically in the Oracle installation directory of PRODUCT\11.2.0\DBHOME_1\ODP.NET\BIN\2. x). However, when the program runs, the most likely situation is, Oracle.DataAccess.Client.OracleException error: The provider is incompatible with this version of the Oracle client ( General check that the native Oracle's Oracle.DataAccess.dll and the Oracle.DataAccess.dll version you are referencing are not consistent, and replacing the same version will solve the problem).
The following main introduction, do not need to install Oracle client, through the latest odp.net mode (Oracle.ManagedDataAccess.dll) directly connected to the Oracle database.

Oracle Fully managed Drive Oracle.manageddataaccess

Oracle's official website provides C # with a new odp.net-mode full-managed driver oracle.manageddataaccess, and EF supports distributed transactions, official website (the address is not very good to find, download time requires an Oracle account to line, If not, register a very fast)-Portal: http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html,:

Download unzip to find the Oracle.ManagedDataAccess.dll we need, if you use the EF framework, select the DLL in EF6:

Refer the Oracle.ManagedDataAccess.dll to our project, and then verify that the link Oracle is connected successfully.

Code snippet:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Data;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 usingOracle.ManagedDataAccess.Client;8 9 namespaceForbiddentoolsTen { One     class Program A     { -         Static voidMain (string[] args) -         { theConsole.title ="oracel Connection Test"; -             stringConnString =@"Data source= (description= (address= (PROTOCOL=TCP) (host= server IP address) (port=1521) (connect_data=) (service_name = server name ))); User id= username; password= password;"; -OracleConnection conn =NewOracleConnection (connstring); - Conn. Open (); +             if(Conn. state = =ConnectionState.Open) -             { +                 stringsql =@"Select Sysdate from dual"; AOracleCommand cmd =NewOracleCommand (SQL, conn); at Console.WriteLine (cmd. ExecuteScalar ()); - Conn. Close (); -             } - Console.readkey (); -         } -     } in}

PS: If in doubt, please leave a message, without permission, may not be reproduced privately, reproduced please indicate the source: http://www.cnblogs.com/xuliangxing/p/8391547.html

How to connect to an Oracle database without the Oracle client installed in C #

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.