Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
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 8-Nov-12 3:16am
Comments
Sastry_kunapuli at 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
good
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
  Permalink  
Rate this: bad
good
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.http://stackoverflow.com/a/372739/649524
  Permalink  

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



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