Re: Getting connectionstring from web.config when in a dll
- From: "Andy B." <a_borka@xxxxxxxxxxxxx>
- Date: Thu, 5 Mar 2009 04:05:41 -0500
I'm using a SqlDataReader to do data access. I use an SqlConnection object
for the connection. So, I can do just like I do in the web application in
the dll and do something like:
dim SqlConnection as new
SqlConnection(ConfigurationManager.ConnectionStrings("eternityrecordsonlineConnectionString").ToString())
"sloan" <sloan@xxxxxxxxx> wrote in message
news:%23hwQv7RnJHA.5228@xxxxxxxxxxxxxxxxxxxxxxx
Ok, I didn't see you're talking about connection strings.
Here you go:
c#
ConnectionStringSettingsCollection connectionStrings =
ConfigurationManager.ConnectionStrings;
foreach (ConnectionStringSettings c in connectionStrings)
{
string connectionStringName = c.Name;
string connectionString = c.ConnectionString;
string providerName = c.ProviderName;
Console.Writeline(connectionStringName);
}
vb.NET
Dim connectionStrings As ConnectionStringSettingsCollection =
ConfigurationManager.ConnectionStrings
Dim connection As ConnectionStringSettings
For Each connection In connectionStrings
Dim connectionStringName As String = connection.Name
Dim connectionString As String = connection.ConnectionString
Dim providerName As String = connection.ProviderName
Debug.Print(connectionStringName)
Next connection
"Andy B." <a_borka@xxxxxxxxxxxxx> wrote in message
news:ehye2kQnJHA.864@xxxxxxxxxxxxxxxxxxxxxxx
How do you get into the web.config from in a dll?
"sloan" <sloan@xxxxxxxxx> wrote in message
news:el02DYQnJHA.3380@xxxxxxxxxxxxxxxxxxxxxxx
The lower "layers" should be able to access the presentation layer
config settings automatically.
Here is a nice write up on some other options:
http://www.eggheadcafe.com/tutorials/aspnet/e54f2d32-72c4-4d2b-b180-c1f564b41f85/some-aspnet-20-configur.aspx
"Andy B." <a_borka@xxxxxxxxxxxxx> wrote in message
news:O8dbGHQnJHA.1248@xxxxxxxxxxxxxxxxxxxxxxx
I have a web application project called Website. I have a dll project
called Categories in the same solution in vs2008. How do I get code in
the Categories project to access connection strings in the
Website.web.config file?
.
- Follow-Ups:
- References:
- Prev by Date: Custom Control.
- Next by Date: RE: So then is there any way to access the container contols
- Previous by thread: Re: Getting connectionstring from web.config when in a dll
- Next by thread: Re: Getting connectionstring from web.config when in a dll
- Index(es):
Relevant Pages
|