I have a dll that uses Entity Framework 6 to perform some database operations. I use the first approach to the database. The model and everything related to the Entity Framework, as well as the connection string in App.config, were created using wizzard in Visual Studio.
So, I compiled the dll and put it along with the corresponding .config in the folder where the application using the dll is waiting.
Everything works fine until I get to the point where the actual database call is made. There I get an error message:
Cannot find connection string for MyDatabaseEntity
The automatically generated connection string, as I said, is a DLL configuration file. I cannot change the app.config of the application. But the application passes an object that has all the information I need to build the connection string. Therefore, I am looking for a way to set the connection string in the code without relying on the configuration file. However, all the tutorials that I find for the first approach to the database use this method. I found a message here that simply says the connection string as a parameter when creating an object of type
MyDatabaseEntities = new MyDatabaseEntities(dbConnect);
but 'MyDatabaseEntities' does not have a constructor that accepts any parameters
public partial class MyDatabaseEntities : DbContext { public MyDatabaseEntities() : base("name=MyDatabaseEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<MyTable> MyTable { get; set; } }
source share