I've been working with EF6 beta 1 code first with dotConnect for oracle version 7.7.257.6 for a while. Every thing works fine if I use an App.config with a WPF app or a web.config with a web application. Currently I'm writing a console app similar to EF migrate.exe to handle multiple database migrations. I need to get connection string from web.config from each of the web sites and provide to MyDbContext object. I created a constructor as follow:
public MyDbContext(string connectionString): base(connectionString)
{
}
When I pass "server=192.168.20.86;direct=True;sid=DB;user id=a;Password=b;" to the connectionString, I get an error : Keyword not supported: 'direct'. If I pass a Sql server connectionString, it works great.
thanks
JL
Keyword not supported: 'direct'
Re: Keyword not supported: 'direct'
1. Make sure that dotConnect for Oracle is used when the "Keyword not supported: 'direct'" exception occurs (check the call stack).
2. Please send us a small test project so that we can reproduce the issue in our environment.
2. Please send us a small test project so that we can reproduce the issue in our environment.
Re: Keyword not supported: 'direct'
public DbContext(string nameOrConnectionString) only takes ConnectionStringName or ConnectionString. It uses Sql server provider by default. How do I tell it to use dotConnect for oracle provider?
Re: Keyword not supported: 'direct'
Problem resolved!
Switched to use public DbContext(DbConnection existingConnection,bool contextOwnsConnection).
public MyDbContext(DbConnection connection): base(connection, contextOwnsConnection: false)
{
}
EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();
ecsb.Provider = provider;
ecsb.Metadata = "None"; // required
ecsb.ProviderConnectionString = connectionString;
EntityConnection conn = new EntityConnection(ecsb.ToString());
var context = new MyDbContext(conn);
thanks
JL
Switched to use public DbContext(DbConnection existingConnection,bool contextOwnsConnection).
public MyDbContext(DbConnection connection): base(connection, contextOwnsConnection: false)
{
}
EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();
ecsb.Provider = provider;
ecsb.Metadata = "None"; // required
ecsb.ProviderConnectionString = connectionString;
EntityConnection conn = new EntityConnection(ecsb.ToString());
var context = new MyDbContext(conn);
thanks
JL
Re: Keyword not supported: 'direct'
Oops! It only solved the problem partially. MyDbContext and data access code are working correctly. Database Migration still doesn't work. Following code generates errors
var connectionInfo = new DbConnectionInfo("server=192.168.20.86;direct=True;sid=DB;user id=a;Password=s;", "Devart.Data.Oracle");
var configuration = new Configuration { TargetDatabase = connectionInfo };
var migrator = new DbMigrator(configuration);
migrator.Update();
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Keyword not supported: 'SERVICE_NAME'.
at System.Data.Common.DbConnectionStringBuilder.get_Item(String keyword)
at Cityworks.DataAccess.CwDbContext.InitCwDbContext()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at System.Data.Entity.Infrastructure.DbContextInfo.<CreateActivator>b__2()
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo)
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbConnectionInfo connectionInfo)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at Cityworks.DataAccess.DbMgrData.GetDatabaseVersion(CwDbVersion model) in c:\CWSource\Cityworks Server\Cityworks.DataAccess\Migrations\DbMgrData.cs:line 230
the internal code of DbMigrator creates another MyDbContext object using the default contructor of MyDbContext, instead of the one below that worked correctly
public MyDbContext(DbConnection connection): base(connection, contextOwnsConnection: false)
{}
var connectionInfo = new DbConnectionInfo("server=192.168.20.86;direct=True;sid=DB;user id=a;Password=s;", "Devart.Data.Oracle");
var configuration = new Configuration { TargetDatabase = connectionInfo };
var migrator = new DbMigrator(configuration);
migrator.Update();
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Keyword not supported: 'SERVICE_NAME'.
at System.Data.Common.DbConnectionStringBuilder.get_Item(String keyword)
at Cityworks.DataAccess.CwDbContext.InitCwDbContext()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at System.Data.Entity.Infrastructure.DbContextInfo.<CreateActivator>b__2()
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo)
at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbConnectionInfo connectionInfo)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
at Cityworks.DataAccess.DbMgrData.GetDatabaseVersion(CwDbVersion model) in c:\CWSource\Cityworks Server\Cityworks.DataAccess\Migrations\DbMgrData.cs:line 230
the internal code of DbMigrator creates another MyDbContext object using the default contructor of MyDbContext, instead of the one below that worked correctly
public MyDbContext(DbConnection connection): base(connection, contextOwnsConnection: false)
{}
Re: Keyword not supported: 'direct'
Please try using
instead of
Code: Select all
public MyDbContext(): base(GetConnection(), contextOwnsConnection: false)
{
}
private static DbConnection GetConnection() {
EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();
ecsb.Provider = "Devart.Data.Oracle";
ecsb.Metadata = "None"; // required
ecsb.ProviderConnectionString = "connectionString...";
EntityConnection conn = new EntityConnection(ecsb.ToString());
return conn;
}
var context = new MyDbContext();
Code: Select all
public MyDbContext(DbConnection connection): base(connection, contextOwnsConnection: false)
{
}
EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();
ecsb.Provider = provider;
ecsb.Metadata = "None"; // required
ecsb.ProviderConnectionString = connectionString;
EntityConnection conn = new EntityConnection(ecsb.ToString());
var context = new MyDbContext(conn);