Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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.

Thanks!
Posted
Comments
S@53K^S 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

You can also store the connection string in a text file, and can access it when needed by reading the text file programatically
 
Share this answer
 
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.http://stackoverflow.com/a/372739/649524
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900