I’ve written an application that is (maybe unnecessarily) tiered on several levels. There are two separate applications, one a UI and one a Windows service; both have the actual code that drives the application in a shared project (so when I update how the app runs, I don’t have to update code in both the UI and the service). In addition to the shared operating code, the shared project also contains the base class and an interface that defines an API for other plugin modules (class projects) that can be added, snoozed, run immediately, etc. All the UI/service does is tell each plugin to run, then emails the results that each plugin generates.
I would like to be able to generate separate data models within those plugin projects, in addition to the main data model in the shared project. Reason for this is, I don’t want to have to reinstall my service every time I want to add a new table for a plugin; by keeping the data model inside the plugin, I can just refresh the plugin and leave the service or the UI running. I’m having trouble getting past the “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.” error. I’ve already copied my plugin’s connection string from its app.config file to the shared project’s app.config file, and to the UI’s app.config file. I’ve even copied the .edmx file from the plugin to the shared project and the UI project. And yet I’m still coming up with this error. I’m wondering if it has anything to do with the .csdl, ssdl, and .msl files referenced in the connection string (eg. res://*/ATS.csdl). I see those files in the \obj\Debug\edmxResourcesToEmbed directories of all three projects where I have my .edmx file, but despite every piece of information I know to copy being everywhere I can think to copy it, I still can’t connect to the database with my plugin. Any ideas?
ETA: I found if I copied the connection string verbatim from the app.config file and specified it when creating a new entity object, it successfully created the connection and was able to query the database. So it seems that some app.config somewhere doesn’t have the connection string, but all the ones that should need it have it.
ETA 2: I turned on symbol debugging and dug into the exact part of System.Data.EntityClient.EntityConnection where it was failing. It’s looking at the ConfigurationManager.ConnectionStrings collection, but the _items member (which I would expect to contain all the Connection Strings listed in my app.config file) contains only a “LocalSqlServer” entry for a SQLEXPRESS database. So of course when it tries finding the connection string under the name I specified, it can’t because whatever configuration file it’s reading doesn’t contain that. Still looking for a way to make this work correctly…
I think I solved the problem, though it’s a kludgy solution and I’d love to see if can be done more elegantly. However, here’s what I ended up doing, thanks to a hint from Kamyar:
In my symbol debugging, I started nosing around in the
EntityConnectionclass, and I noticed that .NET wasn’t picking up the connection strings from my config file like I thought it should have. Kamyar suggested creating a.dll.configfile for the plugin, which I did and it still didn’t work…but only because the entity framework was looking for a config file for the host executable, not the plugin dll. So I coped the host application’sapp.configfile into the directory where my standalone plugins were loading from, named it[Application].exe.config, and it picked it right up.I’m wondering if there’s a better way of doing it, somewhere I could specify a config file that all my plugins should reference rather than a copy of the host’s config file, but I’m just happy not to have to specify a connection string in my code.