Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2007, 07:12 PM
Authorized User
 
Join Date: Jan 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access web.config from a dll

The scenario: a site which uses Flash for the front end, and Flash remoting for handling database calls between Flash and the server. There are also some admin aspx pages for maintaining the database. The connection string is stored in web.config, which allows me to call it from various aspx pages like this:
Code:
string _connString = ConfigurationManager.ConnectionStrings["VideosConnectionString"].ConnectionString;
All the remoting calls are stored in a dll.

Question: is there a way to access the connection string in web.config from the dll? Adding a 'using System.Configuration' statement to the dll doesn't work. I've hard-coded the connection string inside the dll, but it would be nice if it only had to be specified in web.config. :)

Rob
 
Old March 15th, 2007, 08:50 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Its kinda late here so im not thinking very cleary, so I am not sure if this will point you in the right direction but, in DLL's when i want to reference say, a physical path on the server with Server.MapPath() I have to do HTTPContext.Current.Server.MapPath() Look into that class and see if it has the functionality for pulling the connection strings.

post back if not and Ill take a look at it tomorrow when i have had some well earned sleep ^^

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 16th, 2007, 10:58 PM
Authorized User
 
Join Date: Jan 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Doug,

I've looked into HTTPContext.Current.Server.MapPath(), and I'm not sure if this is the solution. One problem is that I get a compile error when I build the dll:

"The type or namespace name 'HttpContext' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)"

Adding a "using System.Web" line doesn't help. That's part I can't figure out: how do you get a .dll to know it's being used in a web application
 
Old March 20th, 2007, 09:53 PM
Authorized User
 
Join Date: Jan 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After wading through a mountain of inaccurate solutions on various web sites (have you noticed how common that is?), I finally figured it out.

If you are using VS 2005, ASP.NET 2.0 with C# and you want to retrieve a connection string from web.config, you can use ConfigurationManager:
Code:
string _connString = ConfigurationManager.ConnectionStrings["VideosConnectionString"].ConnectionString;
However, you have to do two things first:

1. Add "using System.Configuration;" to the class file.

2. In Solution Explorer, right-click on the References folder and select "Add Reference". From the Add Reference dialog, select the ".NET" tab and select "System.Configuration" from the Component Name list.





Similar Threads
Thread Thread Starter Forum Replies Last Post
web.config vs. app.config darlo Visual Studio 2005 11 August 20th, 2008 07:23 AM
Using DLL with its own .config in ASP.NET App robzyc ASP.NET 2.0 Basics 3 April 25th, 2008 02:32 AM
Blog - Web.Config Settings for Access Database kanzeon4 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 April 5th, 2008 07:46 AM
dll config files - included in the build stuarth General .NET 1 July 20th, 2005 06:42 AM
dll config files - included in the build stuarth VS.NET 2002/2003 0 July 13th, 2005 06:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.