sappygolucky
New Member
.. for an ASP.NET DLL.<BR><BR>I have an ASP.NET page that uses a code-behind page. This code-behind page uses a custom Namespace that I've developed.<BR><BR>The problem I'm running into is that, locally, while I'm developing the path to my Access database is:<BR>c:inetpubwwwrootfmdatabase.mdb<BR><BR>On my hosting company's server, it is:<BR>c:inetpub27secondsfmdatabase.mdb<BR><BR>I've resolved to have 2 lines in the DLL - one commented out, depending on the server I'm working from. When I go to move the DLL to production, I switch the commented lines and recompile.<BR><BR>Thoughts that I've had are:<BR>1) Putting the path into the global.asa and passing it into an Init() function. But, that mucks with my CUser object because I've overloaded the New() subroutine to allow you to retrieve a user by doing:<BR>Dim oCUser As CUser = New CUser("user_name")<BR><BR>So, I can't have it inited unless I create a reference to the DB object and pass that into the class. Which, I think is pretty YUCK!<BR><BR>2) Same thing as #1, but just hardcoding the DLL reference into the ASP.NET page (infinite YUCK!).<BR><BR>3) Storing the settings into an XML file and getting the data from that in the DLL. But, I'm in a catch-22 here -- I need to know the path to the XML file in order to open the XML file to get the path .......<BR><BR>I've tried importing the System.Web.Forms.Application class and using the Application.ExecutablePath() function, but that gives me a reference to some ASPNET_wp.exe file or something. I've tried not providing a path in the XmlDocument.Load(), but that defaults to c:winntsystem32.<BR><BR>My preference is to do something along the lines of #3 and not #1. Because my final goal is to take the DLL that I've created and actually split that out into a data layer and a business layer. But, it just seems to kill me that I've have information about my database be passed in from the presentation layer.<BR><BR>So, any ideas are greatly appreciated!Store the connection string in global.asax and then, from your component, you can grab the connection string very easily using ConfigurationSettings.GetConfig. AN example of this in C# is as follows:<BR><BR>NameValueCollection context = (NameValueCollection)ConfigurationSettings.GetConf ig("WebForumsSettings");<BR>_str = context["connString"];<BR><BR>This assumes that your Web.config has a configuration section named WebForumsSettings, i.e.:<BR><BR><configuration><BR> ...<BR><BR> <system.web><BR> ...<BR> </system.web><BR><BR> <WebForumsSettings><BR> <add key="connString" value=http://aspmessageboard.com/archive/index.php/"..." /><BR> </WebForumsSettings><BR></configuration>I don't think you mean global.asax.I can't read.. but, I'm still not crazy about the presentation layer defining the database. I thought the point of the data layer was to completely encapsulate that.<BR><BR>But, I guess, I could, generically, put the site's root path into the web.config and then, if the data layer wants it, it can use that as a basis for where the database is.<BR><BR>But, this is probably just much to-do about nothing.<BR><BR>Ok, now onto your suggestion. I've had some problems with it.<BR><BR>First, when I made the web.config have a WebForumsSettings node, I got an error:<BR>Parser Error Message: Unrecognized configuration section 'WebforumsSettings'<BR><BR>Is there something in the global.asax that I need to do to define the custom settings node?<BR><BR>I was able to put the keys into the appSettings node that comes with the global.asax and then just use the call:<BR>ConfigurationSettings.AppSettings("FM_ConnString")<BR><BR>It gave me the value from the web.config -- but, if I'm able to organize the settings into logical groups, as you eluded to, that would be much cooler.<BR><BR>Thanks for you help so far! It was a huge help!