Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2008, 05:56 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default Using DLL with its own .config in ASP.NET App

Hi Guys,

I am back with another question! (following on from my last one).

I have a DLL which forms (or will form) all of our basic implmentation required for a suite of apps being developed, some will be Windows based, others Web.

Part of this involves Data Access, where of course the databases can be moved. Therefore, the connection strings are stored in a app.config file.

My question is, when working with an ASP.NET app, the app.config is of course Web.config. How do I tell it what connection strings to pass to the DLL that is referenced? It doesnt seem to be reading from the .config file sat with it?

Many thanks,

Rob
http://robzyc.spaces.live.com
__________________
Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
  #2 (permalink)  
Old April 24th, 2008, 09:31 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Where is the config file the DLL expects? Is it in the DLL project? Is it getting moved to the output directory? In a VS project, you can specify that a file be copied to the output directory. Even for a class library, when this is set up, all the output file from the library, including the config file, will get moved to the output directory of the web app as well.

I would recommendation not relying on this kind of architecture. I prefer to have the application define the things like connections and to build the libraries to expect this information when they are constructed. So you put the connections and such in your web.config (being the application) and pass that info to the assemblies that require it. (To use a ridiculously extreme example: there is no config file for the SqlConnection class, we pass the connection string to it.)

-Peter
peterlanoie.blog
Reply With Quote
  #3 (permalink)  
Old April 24th, 2008, 09:49 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Peter,

Thanks for the reply. I agree, I am re-thinking the architecture behind all this. It looks like my boss would prefer me to actually define the platform as a Web Service anyway, due to the number of clients running it. The service will then be hosted on our servers, so if we need to patch it, we can do. Wheras if it were a DLL, then it would need to be patched on each and every server.

The current setup is: DLL output, with the config file next to it (so it pulls the settings from the dllname.dll.config file in the same directory).
I then moved the DLL file, and accompanying config file to the bin directory on the a website. When trying to execute a method within the DLL, it then fell over as it was unable to retrieve the connection string.

I have been doing some more digging, and there are several sites suggesting that if I place settings in the AppSettings section of the DLL's config, and the ConnectionStrings in the ConnectionStrings section of the DLL's config, I should then be able to copy these entries to the Web.config when the DLL is hosted on a web server. However, I can't seem to get this to work either...

Seems odd, I would have expected this sort of process to work, since its common across both Windows and Web based applications?

Rob
http://robzyc.spaces.live.com
Reply With Quote
  #4 (permalink)  
Old April 25th, 2008, 02:32 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Guys,

Been doing some more playing with this, looks like I was experiencing some problems due to use the "settings" property page to create a settings file. When using this, all worked fine when the testing the DLL, but all seemed to go screwy when working with something else (i.e. settings not being picked up at all).

I have now reorganised the app.config for the DLL so the connection strings are in the ConnectionStrings node, and the settings in the AppSettings are in the AppSettings node. This appears to work ok as I have a test app, which fails until I copy the elements into the Test Apps app.config. I am assuming this will work the same for web.config, but we will have to see!

Begs the question now, what happens in the case of a naming conflict? :D

PS: Should have also noted I am accessing the settings/connection strings using ConfigurationManager.AppSettings/ConnectionStrings.

Rob
http://robzyc.spaces.live.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
post xml data from ASP.NET app to ASP app polekat Classic ASP Professional 2 January 31st, 2007 08:44 AM
asp.net machine.config shs BOOK: Beginning ASP.NET 1.0 0 March 25th, 2004 11:01 PM
Porting a sa,ple ASP CR viewer app to ASP.NET jhansen42 Crystal Reports 0 August 29th, 2003 10:26 AM



All times are GMT -4. The time now is 09:36 PM.


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