The client uses C # And odp.net to connect to the server Oracle

Source: Internet
Author: User
Tags oracleconnection oracle developer

Oracle. dataaccess. dll has versions 2. x and 4. x, and 2.x is used for vs2008 development.

The required DLL can be copied from the installed Client

 

Because Microsoft is. in net framework4, system. data. oracleclient. DLL deprecated, and in terms of access efficiency and speed, system. data. oracleclient. DLL and Oracle. dataaccess. compared with DLL, Microsoft does not have the advantage of class libraries provided by Oracle, so I gave up using the system for many years. data. oracleclient. DLL, replaced by odp.net. However, the advantages of ODP. Net include:

1. Oracle on the server can be accessed without installing the client (assuming that the application server is separated from the DB Server)

2. You do not need to configure the tnsnames. ora File

Of course, the main reason I chose ODP. NET is performance. This articleArticleLists the comparison between the two. Technical Comparison: ODP. Net versus Microsoft oracleclient

The following describes how to use ODP. net in a new project. Environment configuration: machine A, run C #ProgramNo Oracle products are installed, such as Oracle databases or clients. Machine B runs an Oracle9i database, and no other Oracle products are installed.

First download ODP.. Net file. You can download the Oracle Data Access Components (odac) downloads on this page. I downloaded the Oracle 11g odac 11.1.0.7.20 with Oracle Developer Tools for Visual Studio.

After the download is complete, you do not need to install oracle. dataaccess. DLL file from odtwithodac111_unzip zip/stage/components/oracle. ntoledb. decompress the ODP _ net_2/11.1.0.7.10/1/datafiles/filegroup4.jar file, copy it to the project, and add Oracle references. dataaccess. DLL.
Write as follows:Code:

Using Oracle. dataaccess. client;

...

String connstring =

"Data Source = (description = (address = (Protocol = TCP) (host = 192.168.0.100) (Port = 1527)" +

"(CONNECT_DATA = (SID = orcl); User ID = sys; Password = sys;"; // This can also be placed in Web. config.

Using (oracleconnection conn = new oracleconnection (connstring ))

{

Conn. open ();

String SQL = "select * from users ";

Using (oraclecommand comm = new oraclecommand (SQL, Conn ))

{

Using (oracledatareader RDR = comm. executereader ())

{

While (RDR. Read ())

{

Console. writeline (RDR. getstring (0 ));

}

}

}

}

After the code is compiled, several DLL files need to be extracted from the downloaded package.
1. OCI. DLL (in the jar file, it is called 'oss. DLL. dbl', remove it after taking it out. DBL in odtwithodac111_20.zip/stage/components/oracle. RDBMS. RSF. IC/11.1.0.7.0/1/datafiles/filegroup2.jar)
2. oraociicus11.dll (in odtwithodac111_unzip zip/stage/components/oracle. RDBMS. IC/11.1.0.7.0/1/datafiles/filegroup3.jar)
3. oraops11w. dll (in odtwithodac1120.20.zip/stage/components/oracle. ntoledb. ODP _ net_2/11.1.0.7.10/1/datafiles/filegroup3.jar)

Below are three people who say they need it. Some people say they don't need it, and they don't need it anyway. Let's continue:
4. orannzsbb11.dll (in odtwithodac1120.20.zip/stage/components/oracle. LDAP. RSF. IC/11.1.0.7.0/1/datafiles/filegroup1.jar)
5. oraocci11.dll (in odtwithodac1120.20.zip/stage/components/oracle. RDBMS. RSF. IC/11.1.0.7.0/1/datafiles/filegroup3.jar)
6. ociw32.dll (in the jar file, it is called 'oss 32. DLL. dbl', remove it after taking it out. DBL in odtwithodac111_20.zip/stage/components/oracle. RDBMS. RSF. IC/11.1.0.7.0/1/datafiles/filegroup2.jar)
Finally, copy the DLL to the project. The CS file must be in the same folder as the EXE file. The B/S file has a dedicated bin directory.

Of course, using a new technology will inevitably encounter some errors: The following is what I encountered:

1. When this exception occurs during running, the prompt 'the provider is not compatible with the version of Oracle client' should be avoided. Check whether the DLL used above is complete.

2. "The requested. NET Framework data provider cannot be found. It may not be installed ." The error message is that Oracle. dataaccess. dll cannot be found in machine. config.

<Dbproviderfactories> </dbproviderfactories>

Is OK.

<Add name = "ORACLE data provider. net "invariant =" oracle. dataaccess. client "Description =" ORACLE data provider. net "type =" oracle. dataaccess. client. oracleclientfactory, Oracle. dataaccess, version = 2.111.7.20, culture = neutral, publickeytoken = 89b483f429c47342 "/>

Note: If the downloaded DLL is not odtwithodac11000020, it is possible that the DLL is not located as mentioned above. You need to find it one by one.

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.