Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

connection string in Web.Config

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John A Grandy - 16 Feb 2006 00:01 GMT
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>
brians[MCSD] - 16 Feb 2006 00:30 GMT
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.ConnectionString);

Signature

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

> If a SQLDataSource add the following to my web.config file, how to I
> programmatically extract the connection string:
[quoted text clipped - 11 lines]
>
> </connectionStrings>
brians[MCSD] - 16 Feb 2006 00:49 GMT
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"]);

Signature

brians
http://www.limbertech.com

> Hello John,
>
[quoted text clipped - 24 lines]
> >
> > </connectionStrings>
rabram66@yahoo.com - 26 Feb 2006 13:26 GMT
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.ConfigurationManager.AppSettings'

Is there something I should be doing differently in asp.net 2.0?
Juan T. Llibre - 26 Feb 2006 16:57 GMT
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/doc/management/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/
===================================
>I tried to use:
> SqlConnection conn = new
[quoted text clipped - 7 lines]
>
> Is there something I should be doing differently in asp.net 2.0?
John A Grandy - 16 Feb 2006 02:08 GMT
Yes. I am doing 2.0 , so this is what I want. Thanks.

> Hello John,
>
[quoted text clipped - 24 lines]
>>
>> </connectionStrings>
rabram66@yahoo.com - 26 Feb 2006 13:22 GMT
> Yes. I am doing 2.0 , so this is what I want. Thanks.
>
[quoted text clipped - 30 lines]
> >>
> >> </connectionStrings>
blackstaronline.net - 16 Feb 2006 00:34 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.