How to write plugin config for database connections?

Aug 26, 2012 at 7:34 PM

I am developing an new hydrodesktop plugin, and I am using sqlite for my data storage. Then I got the problem that the database connection did not work. And I guess the problem may come from the app.config file, because I noticed that there are some difference in scheme between my auto-generated config and those in the origin plugins.

Next is the auto-generated config:

<?xml version="1.0" encoding="utf-8"?>
    <add name="EarlyWarningSettingsEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string='data source=&quot;D:\SOFTWARE\Dotspatial\HydroDesktop 6.28\HydroDesktop 6.28\EarlyWarningSettings&quot;'" providerName="System.Data.EntityClient" />

So, how can I modify the file to make the connection works?

Aug 28, 2012 at 3:50 PM



We are in the midst of a transition period for the HydroDesktop development team. Someone will answer your questions as soon as possible. Thank you for your patience and sorry for any inconvenience. 

Aug 28, 2012 at 4:49 PM

Can you give some more information about your project? Does the plugin load at all? - Dan

Aug 29, 2012 at 5:02 AM


It looks that you are using Entity Framework to work with your local database, is it? Can you show what error you got? It may be whatever...

Aug 30, 2012 at 5:08 AM

Well, thank you.

This is the error message I got.

"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."

Aug 30, 2012 at 7:16 AM
Edited Aug 30, 2012 at 7:18 AM

When you create your ObjectContext (EarlyWarningSettingsEntities) you should use code like this:

var configPath = GetType().Assembly.Location;
var config = ConfigurationManager.OpenExeConfiguration(configPath);
var connectionString = config.ConnectionStrings.ConnectionStrings["EarlyWarningSettingsEntities"];
var container = new EarlyWarningSettingsEntities(connectionString.ConnectionString);
// Work with container....

In this case your plugin will read connection string from app.config for your plugin.

Sep 17, 2012 at 1:20 PM

Well, thank you very much.