Re: Getting connectionstring from web.config when in a dll

Tech-Archive recommends: Fix windows errors by optimizing your registry



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?










.



Relevant Pages

  • Re: Can i pass a SqlConnection object with opened connection to a method/function as a parameter?
    ... methods in your long concatenated string, ... DataTools.EscapeMask method (a static method, apparently), or the ... > connection and what you do with it when you get it ... >> the existed opened sqlconnection object to do it and pass the object to ...
    (microsoft.public.dotnet.framework)
  • Re: ADO connections question
    ... Function CreateADOObjects(ConnectionString as string) ... you'll see this error if the connection has not been ... I have a specific login form that calls the dbLogin function as shown ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Nochmals Treeview
    ... private void button1_Click(object sender, System.EventArgs e) { ... private void TabelleAnlegen(string strDBPfad, string strDB, string strTabellenName){ ... OleDbConnection connection = new OleDbConnection; ... OleDbCommand command = new OleDbCommand; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: ExecuteReader requires an open and available Connection.
    ... you have ALL your users sharing one connection. ... Public Shared Function GetServerAs String ... Dim theServer As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Error using Login control ASP.NET App_Data Folder
    ... the UserInstance type of connection string is for SQLEXPRESS only and is ... Server Management Studio and use a standard connection ... An error has occurred while establishing a connection to the server. ... SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, ...
    (microsoft.public.dotnet.framework.aspnet)