问题
Hello i have a project which the developer uses
conn1 = new OleDbConnection("Provider=MSDAORA; Data Source=example;User ID=test;Password=test;Unicode=True");
conn1.Open();
I have problem with that provider MSDAORA and i think it's old So i want to Connect to my database with another easy solution without MSDAORA.
Thank you
回答1:
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();
}
}
回答2:
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="DATA SOURCE=YOUR_SOURCE_HERE;PASSWORD=YOUR_PASSWORD_HERE;PERSIST SECURITY INFO=True;USER ID=YOUR_USER_ID_HERE"" providerName="System.Data.EntityClient" />
回答3:
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/
来源:https://stackoverflow.com/questions/11365469/c-sharp-and-oracle-database-connection