Keyword not supported: 'direct'

Keyword not supported: 'direct'

Postby John Liu » Tue 30 Jul 2013 23:40

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
John Liu
 
Posts: 60
Joined: Wed 14 Nov 2012 20:58

Re: Keyword not supported: 'direct'

Postby Shalex » Wed 31 Jul 2013 06:55

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.
Shalex
Devart Team
 
Posts: 7705
Joined: Thu 14 Aug 2008 12:44

Re: Keyword not supported: 'direct'

Postby John Liu » Wed 31 Jul 2013 15:52

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?
John Liu
 
Posts: 60
Joined: Wed 14 Nov 2012 20:58

Re: Keyword not supported: 'direct'

Postby John Liu » Wed 31 Jul 2013 17:41

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
John Liu
 
Posts: 60
Joined: Wed 14 Nov 2012 20:58

Re: Keyword not supported: 'direct'

Postby John Liu » Wed 31 Jul 2013 23:26

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)
{}
John Liu
 
Posts: 60
Joined: Wed 14 Nov 2012 20:58

Re: Keyword not supported: 'direct'

Postby Shalex » Wed 07 Aug 2013 08:01

Please try using

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();

instead of

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);
Shalex
Devart Team
 
Posts: 7705
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle