I built a class library based on the IssueTracker starter kit. Everything works great except that the issue start kit gets it's connection string from the web.config file. In a class library, you obviously wouldn't have this option so what type of generic object
would you use to store the connection string, + some other application variables. The library will be stored in the GAC so I will need to be able to pass it the connection string from many other application front ends. Thanks, ScAndal
the dll should use the same config file that the host application uses once it's absorbed into the application. if you have a dll, and you call it from an aspx page, the dll will call the configuration settings of that aspx page. afaik. Either that, or I'm
dreaming when it works on my apps. :)
Yes. ConfigurationSettings.AppSettings['whatever'] will automatically figure out whether it reads from a web.config or an app.config file. Is this not the behavior you're looking for?
"Can't sleep, clowns will eat me... can't sleep clowns will eat me, can't sleep clowns will eat me"
Excellent, that is the behavior i'm looking for. The only other thing i'm wondering is this the best way of doing it. It is very possible that i would use different classes from this library throughout all my applications. I'm wondering I should just send the
connection string to each class or if there is some other way that would make this a little more generic? Can anyone think of anything? ScAndal
Just make sure all of your applications contain a key in their config files that your class library uses. You could even go so far as creating a custom config section to make sure that it's unique. Have your class library look for ConfigurationSettings.AppSettings["MyCustomConnectionStringKey"]
and anytime you want to use the library, you just put that key in the config file.
"Can't sleep, clowns will eat me... can't sleep clowns will eat me, can't sleep clowns will eat me"
Ok, counterpoint: NEVER EVER get connection information from the config file, unless you are sure these will never be user specific or user maintainable. Reason: * Your library may be used in a windows application. * The application config resides in the same
directory as the exe then. * Guess what - best practices demand the user CAN NOT WRITE IT. So, he can not connect to another database because he can not change the connection string. Ups. Perfect for most web apps, but a total sin for win apps.
* Configure the value from some loader mechanism. * The website usage just has to read the value from the we.config and put it in. * Any other program can use whatever mechanism it likes. Personalyl we use XML serialized object graphs that go into the proper
location. Prett easy to work with. Oh, and: * READ THE DESIGN GUIDELINES FOR WINDOWS APPLICATIONS. 99.9% of the developers out there are ignorant about them. but stuff like this is in there. Like where to store user specific information.
Thona, how are you using the xml serialized objects? Is it defined in xml in web.config, with a custom section handler, or you have a separate xml file? And oh, one more thing, do you write config class and serialize it or what? Just curious to see what other
people are doing.. ;)
ScAndal
Participant
1304 Points
290 Posts
Handling connection string in Class Library.
Jul 28, 2004 08:57 PM|LINK
.NET Consulting http://www.kineticmedia.net
KraGiE
Star
14567 Points
2926 Posts
Re: Handling connection string in Class Library.
Jul 28, 2004 11:03 PM|LINK
ScAndal
Participant
1304 Points
290 Posts
Re: Handling connection string in Class Library.
Jul 28, 2004 11:05 PM|LINK
.NET Consulting http://www.kineticmedia.net
n1ckP
Member
650 Points
130 Posts
Re: Handling connection string in Class Library.
Jul 29, 2004 12:39 PM|LINK
Nick Patterson
Systems Architect
ScAndal
Participant
1304 Points
290 Posts
Re: Handling connection string in Class Library.
Jul 29, 2004 12:41 PM|LINK
.NET Consulting http://www.kineticmedia.net
n1ckP
Member
650 Points
130 Posts
Re: Handling connection string in Class Library.
Jul 29, 2004 03:20 PM|LINK
Nick Patterson
Systems Architect
thona
Member
20 Points
2923 Posts
Re: Handling connection string in Class Library.
Jul 29, 2004 04:32 PM|LINK
ScAndal
Participant
1304 Points
290 Posts
Re: Handling connection string in Class Library.
Jul 29, 2004 04:52 PM|LINK
.NET Consulting http://www.kineticmedia.net
thona
Member
20 Points
2923 Posts
Re: Handling connection string in Class Library.
Jul 29, 2004 05:18 PM|LINK
christiantoi...
Member
435 Points
86 Posts
Re: Handling connection string in Class Library.
Aug 01, 2004 01:38 AM|LINK
Software Consultant
Dev360.com, LLC