The method of C# connecting to Oracle database (Oracle.DataAccess.Client is also called ODP.net)

First introduce the development environment: WIn10 64bit+Visual Studio 2015+Oracle10ClientWin32 (just the client, it is also possible to install the entire database)

At present, there are 3 ways to connect to Oracle database in C#. The distribution is Microsoft's System.Data.OracleClient, Oracle's Oracle.DataAccess.Client and Oracle's Oracle.ManagedDataAccess.dll (optimal)

1. Microsoft's System.Data.OracleClient can be directly referenced, but VS will prompt that "System.Data.OracleClient.OracleConnection" is out of date, which means that Microsoft itself does not recommend using it, so it is enough to know it, no need to use it

2. C# uses Oracle.DataAccess.Client, also called ODP.net. It is a database access class library provided by Oracle. Its functions and efficiency are guaranteed. It also has a very convenient feature: on the client, it is not necessary to Install the Oracle client and use it directly by copying it. Because Microsoft will deprecated System.Data.OracleClient.dll in .net framework4, and in terms of access efficiency and speed, compared with Oracle.DataAccess.dll, Microsoft does not provide Oracle. Class libraries have advantages, so I gave up on System.Data.OracleClient.dll that I've been using for years and used odp.net instead. However, the advantages of odp.net are not only these, but also include:
1) The oracle on the server can be accessed without installing the client (assuming that the Application Server is separated from the DB Server)
2) There is no need to configure the TnsNames.Ora file

For specific usage, please refer to this hero's http://blog.csdn.net/rrrrssss00/article/details/7178515/

And this hero's http://blog.csdn.net/sumirry/article/details/46746331

If the project needs to be transferred from System.Data.OracleClient.OracleConnection to Oracle.DataAccess.Client, you only need to find Oracle.DataAccess.dll in the oracle installation directory and add a reference, and then use Oracle.DataAccess.Client;
nothing else needs to be done, that is Can.
If user=xxx is useful in the connection string, change it to user id=xxx and remove the original Using of System.Data.OracleClient.

3. Focus on learning the last Oracle.ManagedDataAccess.dll. The second one has many advantages, but it also has disadvantages, that is, to distinguish between x86/x64 versions.

Download dll and use method refer to this hero's http://www.cnblogs.com/yjmyzz/archive/2013/11/01/3400999.html

 

copy code
            OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["OracleConnString"].ToString());
            con.Open();
            OracleCommand cmd = new OracleCommand(cmdString, con);
            OracleDataAdapter oda = new OracleDataAdapter();
            oda.SelectCommand = cmd;
            oda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
copy code

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325476255&siteId=291194637