ChrisMorley

Hi, i have a class library which implements a data access tier. As i used the automated designer for the dataset it automatically added an app.config in the class library with the string to the database:


Code Snippet
Code Snippet<connectionStrings>
<add name="AppDatabase.Properties.Settings.dbConnectionString"
connectionString="Data Source=D:\Chris\rowapp\RowApp\bin\Debug\db.sdf"
providerName="Microsoft.SqlServerCe.Client" />
</connectionStrings>

I then use this data access class library in my main application, however how can i change and update this connection string and point it to a different file at runtime I would like to be able to select a different database but it seems (from breakpoints in the generated table adapter code - InitConnection()) the default values are being called (in this case from the xml app config above). Is this automated, i thought the settings of each class libary used in the main project are copied into the main project app.config file but it seems not, furthermore as mentioned it seems like only the default settings are read.

How can i get, or indeed override the connection string setting for the database, whilst at the same maintain all the other settings which are in place for the main app (ie user preferences, persistent settings etc) I tried creating a setting in the main default application of dbConnectionString, but it always picks up the default one from the AppDatabase class library namespace (the setting is set in the settings class auto generated code via the Configuration.DefaultSettingValueAttribute attribute).

Thanks in advance,

Chris



Re: .NET Framework Data Access and Storage Connection Strings & App.config with class libaries

Adamus Turner

A connection string is not a default value, it's just binded early in the fashion you've mentioned.

Yes, you can late bind a control and change the connection during run time. Using ADO.net, create a new datasource and bind it.

Adamus






Re: .NET Framework Data Access and Storage Connection Strings & App.config with class libaries

ChrisMorley

This is way before data binding this is connection strings and settings. I have found that copying the connection strings section of the xml app.config for the class library into the connection strings section of the app.config file of the main application it seems to work ok.

I guess when accessing the properties and settings through the property manager i will have to use the full namespace reference 'AppDatabase.Properties.Settings.dbConnectionString' rather than just dbConnectionString

How come microsoft does not have an automated way to copy all the class library settings into one composite settings file when the class libaries are referenced from the main application




Re: .NET Framework Data Access and Storage Connection Strings & App.config with class libaries

Adamus Turner

Last question first --> MS provides OOP which allows chlid classes to inherit from a Parent Class.

...and yes, you'll have to fully qualify the string as far back as the object reference.

Adamus