Solved

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

Posted on 2006-10-30
2
228 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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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