C# and Oracle database connection

岁酱吖の 提交于 2019-12-07 15:34:29
Aghilas Yakoub

Try with Oracle provider, add reference to System.Data.OracleClient assembly

use OracleConnection as in this example

string connectionString = "...";
using (OracleConnection connection = new OracleConnection(connectionString))
{
    connection.Open();
    using(OracleCommand command = new OracleCommand(your query))
    {
       command.Connection = connection;
       command.ExecuteNonQuery();
    }
}

I used the latest ODAC (ODP.NET) from oracle and used the following string with an ADO.NET Entity Data Model.

<add name="Entities" connectionString="metadata=res://*/DataTypes.Model1.csdl|res://*/DataTypes.Model1.ssdl|res://*/DataTypes.Model1.msl;provider=Oracle.DataAccess.Client;provider connection string=&quot;DATA SOURCE=YOUR_SOURCE_HERE;PASSWORD=YOUR_PASSWORD_HERE;PERSIST SECURITY INFO=True;USER ID=YOUR_USER_ID_HERE&quot;" providerName="System.Data.EntityClient" />

Seeing as how you asked for an EASY solution, another option that is probably the quickest and dirtiest is to just try and change the provider that is in your connection string. That will keep you from having to go back into your code and adding references to assemblies.

In other words, in your original example, your connection string was:

Provider=MSDAORA; Data Source=example;User ID=test;Password=test;Unicode=True

Try updating the provider to

Provider=OraOLEDB.Oracle; Data Source=example;User ID=test;Password=test;Unicode=True

For more information, check out http://www.c-sharpcorner.com/UploadFile/nipuntomar/connection-strings-for-oracle/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!