Link to home
Start Free TrialLog in
Avatar of incapital
incapital

asked on

Creating production, testing, and development connection strings for a DLL

I'm developing a site using Visual C# 2008. I have a solution with the following projects:

Web site
Business Logic Layer (BLL)
Data Access Layer (DAL)

When I publish the website, the BLL and DAL are compiled into DLLs, and placed in the bin directory of the website.

I want to have the DAL use different connection strings when I deploy the application to development, testing, and production environments. Right now, though, the settings in app.config file for the DAL are embedded into the DLL when it's compiled, rather than read from an external file.

While one could obviously switch all the settings to the production settings before publishing the site, this introduces a high likelihood of error (leaving the development settings on in prod, using production settings in dev, etc). I'd like to have the DAL read its configuration settings in its deployment environment.

How best to do this?
Avatar of Toms Edison
Toms Edison
Flag of India image

if you are using sql server you can create alias with same name in production and development server and use  the alias name in connection string

details on creating alias
http://www.alpesh.nakars.com/blog/howto-configure-port-alias-for-sql-server/


If you are using oracle as backend, you can create an entry in TNSNames.Ora file with connection name same as that of production server but internally you can give the entries for the development machine
details on creating tns names
http://aspen.ithaca.edu:7778/pls/portal/docs/PAGE/TOPLEVELPAGES/ARGUS_HOME_PG/TAB59/ARGUS_RECOURCE_CENTER/INSGNG01.PDF

basically both does the same job and this is what we do to avoid the issue you mentioned


Avatar of incapital
incapital

ASKER

Thank you for your reply. While what you describe would work, I'd prefer to handle this within the application code itself. That would allow me to extend the same solution to other areas of the application (beyond connection strings) if needed.
ok.
If you want to handle that in code then

have a configuration file which stores connection string for production, development and testing servers. Have another configuration that will specify which configuration to use.
in your app.config
<add key="production" value=""/>
<add key="development" value=""/>
<add key="testing" value=""/>
<add key="activeconnection" value ="production"/>

in your code you can do
string activeconnection = ConfigurationManager.AppSettings["activeconnection"];
string connectionstring = ConfigurationManager.AppSettings[activeconnection];

Thank you for the reply. I'll give it a try.
ASKER CERTIFIED SOLUTION
Avatar of incapital
incapital

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial