Solved

Passing the connection string in my web.config to my Data Access Project

Posted on 2006-10-30
2
239 Views
Last Modified: 2010-04-23
I have created a website. My website web.config is storing the connection string to the database. I also have 2 additional class library projects MyWebisteBLL(Business Logic) and MyWebsiteDAL(Data Access Layer).  In my DAL the app.config is storing the connection string for this project.  What is the proper way for the DAL to reference the connection string from the web.config.
0
Comment
Question by:DigitalDan3
[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
2 Comments
 
LVL 8

Accepted Solution

by:
Shakti109 earned 500 total points
ID: 17835868

Are these DLL libraries separate objects as in they are compiled out to true .DLL's and then these .DLL's are referenced in your web project, OR are they just classes you have created in the single web project.

If they are truly separate .DLL's that are then referenced by your root web project, you will need to add the same .config file as a resource to the .DLL.

If they are just classes within the single web-project then you can reference it directly.

Something along the lines of :

Private oDatasource as string
Private aConfig As System.Configuration.ConfigurationSettings
oDatasource = aConfig.AppSettings("DataSource")

This assumes the key in your .config file is named "DataSource".
0
 

Author Comment

by:DigitalDan3
ID: 17837694
These are separate projects that I created in my website solution.  They are DLL's in my Bin folder and their connection string is stored in .config file of the project.  How can I make these DLL's use the connection in the web.config.  I am using the new membership API in VS2005.  The membership API and the Data are on the same database.  I was trying to avoid changing the connection string in 2 different places as I will be working against the live and development data.

Thanks

Dan
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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