Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > connection string in Web.Config

Reply
Thread Tools

connection string in Web.Config

 
 
John A Grandy
Guest
Posts: n/a
 
      02-16-2006
If a SQLDataSource add the following to my web.config file, how to I
programmatically extract the connection string:

<configuration>

<appSettings/>

<connectionStrings>

<add name="GUIDBConnectionString" connectionString="Data
Source=(local);Initial Catalog=GUI;Integrated Security=True"

providerName="System.Data.SqlClient" />

</connectionStrings>


 
Reply With Quote
 
 
 
 
=?Utf-8?B?YnJpYW5zW01DU0Rd?=
Guest
Posts: n/a
 
      02-16-2006
Hello John,

To get that string try:

// Get the connectionString.
ConnectionStringSettings connectionStringSettings =
ConfigurationManager.ConnectionStrings["GUIDBConnectionString"];

Then to use it:
// Initialize the connection with the string
SqlConnection sqlConnection - new
SqlConnection(connectionStringSettings.ConnectionS tring);

--
I think that should do it - brians
http://www.limbertech.com


"John A Grandy" wrote:

> If a SQLDataSource add the following to my web.config file, how to I
> programmatically extract the connection string:
>
> <configuration>
>
> <appSettings/>
>
> <connectionStrings>
>
> <add name="GUIDBConnectionString" connectionString="Data
> Source=(local);Initial Catalog=GUI;Integrated Security=True"
>
> providerName="System.Data.SqlClient" />
>
> </connectionStrings>
>
>
>

 
Reply With Quote
 
 
 
 
blackstaronline.net
Guest
Posts: n/a
 
      02-16-2006
Here is what works for me;

--->In your WEB.CONFIG file
<appSettings>
<add key="DBConn" value="Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\inetpub\wwwroot\data\test.mdb" />
</appSettings>

-->In your page
Dim objConn As OleDBConnection = New
OleDBConnection(ConfigurationSettings.AppSettings( "DBConn"))

Hope this helps,
Jeremy Reid
http://blackstaronline.net/hgtit

 
Reply With Quote
 
=?Utf-8?B?YnJpYW5zW01DU0Rd?=
Guest
Posts: n/a
 
      02-16-2006
Sorry, I am very much in the mindset of ASP.NET 2.0. they have added some
nice additional configuration management features. For 1.1 try:

web.config:
<appSettings>
<add key="ConnectionString" value="server=...;database=...;user id=...;
password=...;" />
</appSettings>

In your connection code:
SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

--
brians
http://www.limbertech.com

"brians[MCSD]" wrote:

> Hello John,
>
> To get that string try:
>
> // Get the connectionString.
> ConnectionStringSettings connectionStringSettings =
> ConfigurationManager.ConnectionStrings["GUIDBConnectionString"];
>
> Then to use it:
> // Initialize the connection with the string
> SqlConnection sqlConnection - new
> SqlConnection(connectionStringSettings.ConnectionS tring);
>
> --
> I think that should do it - brians
> http://www.limbertech.com
>
>
> "John A Grandy" wrote:
>
> > If a SQLDataSource add the following to my web.config file, how to I
> > programmatically extract the connection string:
> >
> > <configuration>
> >
> > <appSettings/>
> >
> > <connectionStrings>
> >
> > <add name="GUIDBConnectionString" connectionString="Data
> > Source=(local);Initial Catalog=GUI;Integrated Security=True"
> >
> > providerName="System.Data.SqlClient" />
> >
> > </connectionStrings>
> >
> >
> >

 
Reply With Quote
 
John A Grandy
Guest
Posts: n/a
 
      02-16-2006
Yes. I am doing 2.0 , so this is what I want. Thanks.

"brians[MCSD]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello John,
>
> To get that string try:
>
> // Get the connectionString.
> ConnectionStringSettings connectionStringSettings =
> ConfigurationManager.ConnectionStrings["GUIDBConnectionString"];
>
> Then to use it:
> // Initialize the connection with the string
> SqlConnection sqlConnection - new
> SqlConnection(connectionStringSettings.ConnectionS tring);
>
> --
> I think that should do it - brians
> http://www.limbertech.com
>
>
> "John A Grandy" wrote:
>
>> If a SQLDataSource add the following to my web.config file, how to I
>> programmatically extract the connection string:
>>
>> <configuration>
>>
>> <appSettings/>
>>
>> <connectionStrings>
>>
>> <add name="GUIDBConnectionString" connectionString="Data
>> Source=(local);Initial Catalog=GUI;Integrated Security=True"
>>
>> providerName="System.Data.SqlClient" />
>>
>> </connectionStrings>
>>
>>
>>



 
Reply With Quote
 
rabram66@yahoo.com
Guest
Posts: n/a
 
      02-26-2006

John A Grandy wrote:
> Yes. I am doing 2.0 , so this is what I want. Thanks.
>
> "brians[MCSD]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello John,
> >
> > To get that string try:
> >
> > // Get the connectionString.
> > ConnectionStringSettings connectionStringSettings =
> > ConfigurationManager.ConnectionStrings["GUIDBConnectionString"];
> >
> > Then to use it:
> > // Initialize the connection with the string
> > SqlConnection sqlConnection - new
> > SqlConnection(connectionStringSettings.ConnectionS tring);
> >
> > --
> > I think that should do it - brians
> > http://www.limbertech.com
> >
> >
> > "John A Grandy" wrote:
> >
> >> If a SQLDataSource add the following to my web.config file, how to I
> >> programmatically extract the connection string:
> >>
> >> <configuration>
> >>
> >> <appSettings/>
> >>
> >> <connectionStrings>
> >>
> >> <add name="GUIDBConnectionString" connectionString="Data
> >> Source=(local);Initial Catalog=GUI;Integrated Security=True"
> >>
> >> providerName="System.Data.SqlClient" />
> >>
> >> </connectionStrings>
> >>
> >>
> >>


 
Reply With Quote
 
rabram66@yahoo.com
Guest
Posts: n/a
 
      02-26-2006
I tried to use:
SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"])
in my connection code, but I got the error message below.

'Public Shared ReadOnly Property AppSettings() As
System.Collections.Specialized.NameValueCollection ' is obsolete: 'This
method is obsolete, it has been replaced by
System.Configuration!System.Configuration.Configur ationManager.AppSettings'

Is there something I should be doing differently in asp.net 2.0?

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      02-26-2006
I have found it easier to give up altogether on appSettings,
and use connectionStrings instead, although you can use either.

For VB and C# examples, see :
http://www.asp.net/QuickStart/aspnet.../retrieve.aspx




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaņol : http://asp.net.do/foros/
===================================
<(E-Mail Removed)> wrote in message news:(E-Mail Removed) oups.com...
>I tried to use:
> SqlConnection conn = new
> SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"])
> in my connection code, but I got the error message below.
>
> 'Public Shared ReadOnly Property AppSettings() As
> System.Collections.Specialized.NameValueCollection ' is obsolete: 'This
> method is obsolete, it has been replaced by
> System.Configuration!System.Configuration.Configur ationManager.AppSettings'
>
> Is there something I should be doing differently in asp.net 2.0?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set the connection pool size in the Sybase connection string? Wei Lu ASP .Net 2 02-16-2009 09:51 AM
Web.config: connection string or connection key? rlueneberg@gmail.com ASP .Net 3 08-03-2007 09:37 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= ASP .Net 2 10-26-2004 02:43 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM
connection string exception : Format of the initialization string does not conform to specification starting at index 0 Gaurav ASP .Net 0 11-07-2003 10:24 AM



Advertisments