Click here to Skip to main content
13,041,887 members (72,909 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have a solution with multiple projects in VS2012. Each project needs access to the same database. I have a DAL which handles all connections and retrieval of data.

What I do need to do is (1). store the connection string in such a way that the DAL can access it during runtime and design time (some WPF forms I have, has bindings to ViewModels which retrieve data from the database during design time and ConfigurationManager.ConnectionStrings returns null as the app.config is located in another project) and (2). If the database is moved to another server in the future, I would like to update my connection string without having to rebuild my solution (config file or module to change and save the connection string during runtime?)

I am not concerned about encrypting the connection string.

Any advice or examples would be appreciated.

Posted 8-Nov-12 3:16am
Sastry_kunapuli 8-Nov-12 9:54am
when you instantiate the DAL try initializing and storing the conn string into a property and use that property for your application.I think vs is intelligent enough get the conn string from a dll
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can also store the connection string in a text file, and can access it when needed by reading the text file programatically
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

app.config is supposed to be per application.

You can store connection string in separate text/xml file. Make sure this file is available during design time. Bindings will work, as long as file exists, and referenced appropriately.

To respond to changes at run time, You need to add a file watcher[^] to the config file.

This is similar to how log4net watches config file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100