I have the following connection string:
<add name="DataContext" connectionString="DATA SOURCE=Server;
PASSWORD=123;USER ID=SYSTEM" providerName="Oracle.DataAccess.Client"/>
My business logic determine I need to read manually the connection string of the database:
class MyDbContext: DbContext
{
public MyDbContext() :
base(ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString){}
...
}
It works properly with Sql Server but when I change to a Oracle Connection string don’t works. It happens because the DbContext tries to use the Oracle ConnectionString to connect on a Sql Server Database because it dinn’t receive the providerName.
Anyone knows how to solve this problem?
To create a DbContext using Oracle without use WebConfig, your inheritance of DbContext must inject an Oracle Connection to base constructor: