1

I have an two exe's that are interacting with the same database. One is the main application, and the other is an updater application (updates the main application). I am trying to keep the installation package limited to one configuration file. IE I want the Updater application to use the main applications config file.

I was able to pull the connection string and create the database context like this:

string entityConnectionString = (entitySettings == null) ? "" : entitySettings.ConnectionString;
var ecb = new EntityConnectionStringBuilder(entityConnectionString);
var ec = new EntityConnection(ecb.ToString());

However, if I do not include the configuation for the updater application below, I get the error The specified store provider cannot be found in the configuration, or is not valid.

<system.data>
  <DbProviderFactories>
    <remove invariant="System.Data.SqlServerCe.4.0"/>
    <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
  </DbProviderFactories>
</system.data>

How do I tell Entity Framework or the application to use the other configuration file or get around this error message? Adding a config file for the updater exe is not an option, as boss man wants one config file. (We want to be able to remotely update the config files and adding multiple makes it more complicated.)

teynon
  • 7,540
  • 10
  • 63
  • 106
  • may be this will help: http://stackoverflow.com/questions/10300063/can-i-create-config-file-and-include-it-to-web-config – vlscanner Oct 04 '13 at 22:02

2 Answers2

1

You can allow multiple projects to share the same app.config as below:

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @"C:\Shared\app.config");
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • @Tom the file name has to be a path (see my answer). – Sam Leach Oct 04 '13 at 22:58
  • I updated it to `string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\MainApp.exe.config"; AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @path);` and I get the same error message. – teynon Oct 04 '13 at 23:06
0

I ended up using this answer:

Add a DbProviderFactory without an App.Config

by extracting the data from the main exe.config and plugging the values in.

Community
  • 1
  • 1
teynon
  • 7,540
  • 10
  • 63
  • 106