Reputation: 3224
I'm trying to pass existing connection to DbContext, but I get this error:
Unable to determine the provider name for connection of type Oracle.DataAccess.Client.OracleConnection
What am I doing wrong here?
var oracleConnectionString = ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
var transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
using (var conn = new OracleConnection(oracleConnectionString))
{
conn.Open();
using (var context = new MainDbContext(conn, false))
{
var cmd = @" some sql commandd here ...";
context.Database.ExecuteSqlCommand(cmd);
context.SaveChanges();
}
}
scope.Complete();
}
Connection string:
<add name="OracleConnectionString" connectionString="Data Source=SERVER;Persist Security Info=True;User ID=USER;Password=PASS" />
Upvotes: 0
Views: 2733
Reputation: 3224
If using Database First, looks like you can't create new DbContext from Oracle connection string, because EF doesn't know, where to look for metadata. You need to use EF connection, instead of Oracle connection. This is what solved it for me:
var efConnectionString = ConfigurationManager.ConnectionStrings["MainDbContext"].ConnectionString;
using (var conn = new EntityConnection(efConnectionString))
{
conn.Open();
using (var context = new MainDbContext(conn, false))
{
}
}
Upvotes: 1
Reputation: 18759
When you have your edmx
file in a different class project, to say your web project, you also need to have the same connection string in the web project.
so...
Class Project:
Web Project
Also, take a look here Problems switching .NET project from unmanaged to managed ODP.NET assemblies in case you're missing some Oracle assemblies.
Upvotes: 1