Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 4.3: 'update-database' when configuration files are separated

Moved to ef 4.3 with

AutomaticMigrationsEnabled = true;

In web.config have the following settings:

<appSettings configSource="appSettings.config" />
<connectionStrings configSource="connectionStrings.config" />

In Package Manager Console execute

update-database -verbose

and got the following error:

System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'connectionStrings.config'

The error is understandable: it tries to open connectionStrings.config file from the working directory which is not the root project directory where connectionStrings.config file exists.

If connectionStrings.config and appSettings.config content to be moved to the web.config all works like a charm.

Is it a bug a it can be solved somehow?

like image 340
sashaeve Avatar asked Dec 31 '25 00:12

sashaeve


1 Answers

When the migrations are run, it appears that binaries and the config file are copied to a temp directory. The files referenced as configSource are not copied over. I've tried marking the configSource files to be copied in the build, to no luck.

I reverted back to putting the connection string right into the app.config of the class library that contains my dbcontext and migrations. I have a separate class library for that, so my web.config of the main web project can still use configSource.

like image 86
Anders Abel Avatar answered Jan 02 '26 12:01

Anders Abel