Using the System.Data.SqlClient provider it is possible to pass a connection string to the DbContext constructor as follows;
public DataContext() //DbContext
{
string ConnString = "Connection String Here";
this.Database.Connection.ConnectionString = ConnString;
Database.SetInitializer<DataContext>(null);
}
Is there a similar way of passing the connection string to the DbContext for the JetEntityFrameworkProvider without using the app.config settings?
In your code, the statement
Database.Connection.ConnectionString = ConnString;
creates a Database.Connection using theApp.Config
(so probably SQL Server in your case) without open it. Then you set ConnectionString of just created connection that is a SQL Server connection. You can change theApp.Config
and create always aJetConnection
or, if you need to connect to different database types, you can use a different overload of DbContextTo use this overload the connection to Microsoft Access Database must be a JetConnection.