oracle-c# Connection Database

Source: Internet
Author: User

System.Data.OracleClient Microsoft-provided connection library, but it is outdated, not recommended

Two. Oracle.DataAccess.Client (odp.net) Oracle provides a database access class library.

Three. Oracle.ManagedDataAccess.dll (Odp.net Managed) is also provided by Oracle.

Scenario 3 is recommended, but if you use manageddataaccess, you must add a reference to the assembly "Netstandard", which is the framework 4.6 and above.

So I am using the. NET Framework 4.5 of the project is not used, the adoption of the second approach, scenario two is to distinguish between the x86/x64 version.

1. Go to the official website to download the required DLL files.

Http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html

Download the corresponding VS version of the DLL file, if the VS version is too low, download the oldest DLL file, the author downloaded the oldest: Odac 11.2 Release 5

Place these DLL files under the bin directory where the project is running, and run the file in the same directory.

Database Connection statement:

  < connectionStrings >    <  name= "oracleconnstring"  connectionString= "Data source= (description= ( Address= (PROTOCOL=TCP) (host=192.168.1.161) (port=1521)) (Connect_data= (sid=myoracle))); Persist Security info=true; User Id=system; password=sky312; " />  </ connectionStrings >

C # calls

Private ReadOnly stringConnStr = configurationmanager.connectionstrings["oracleconnstring"]. ConnectionString;stringsql ="select * from \ "Userinfo\""; OracleConnection Connection=NewOracleConnection (CONNSTR); connection. Open (); OracleCommand command=Neworaclecommand (SQL, connection);D atatable table=NULL;Try{OracleDataAdapter Adapter=NewOracleDataAdapter (); Adapter. SelectCommand=command; Table=NewDataTable (); Adapter. Fill (table);}Catch{    Throw;}finally{command.    Dispose (); Connection.    Close (); Connection. Dispose ();}
Datagridview1.datasource =Table;

Inquire

oracle-c# Connection Database

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.