Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-17
5
Medium Priority
?
741 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:incapital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22744114
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


0
 
LVL 3

Author Comment

by:incapital
ID: 22744875
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.
0
 
LVL 13

Expert Comment

by:TechTiger007
ID: 22745423
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];

0
 
LVL 3

Author Comment

by:incapital
ID: 22757206
Thank you for the reply. I'll give it a try.
0
 
LVL 3

Accepted Solution

by:
incapital earned 0 total points
ID: 22758567
Thank you for your suggestion. The app config file doesn't get deployed with the web site, so that wasn't a viable option.

The solution was to remove the default value that was baked into the dll at compile time, and insert a new value in the web config. I can then point the connection strings settings to read from a local file:

<connectionStrings configSource="myLocal.config"/>

and then myLocal.config contains:

<connectionStrings>
    <remove name="DAL.Properties.Settings.my_connection"/>
    <add name="DAL.Properties.Settings.my_connection" connectionString="Data Source=myDataSource;Initial Catalog=myCatalog;User Id=myUser;Password=myPassword;" />
</connectionStrings>

Mods, please close question at your convenience.
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question