ConfigurationSettings.ConnectionStrings("Personal").ConnectionString does not work

D

Dave

I am a user of the ConfigurationSettings.AppSettings("KeyName") in
asp.net 1.1 so after reading about the new ConnectionStrings collection
in "Intoducing Microsoft ASP.NET 2.0 by Dino Esposito on page 137 I
excitedly started a demo project to try it out. I am getting an error
in the editor. It's telling me that ConnectionStrings is not a member
of System.Configuration.ConfigurationSettings. What am I doing wrong?

Dave
 
G

Guest

Dear Dave,

ConfigurationManager Class
===================
One important new configuration-related class is the ConfigurationManager
class, which provides seamless programmatic access to configuration files and
configuration sections. Using the methods and properties of this class, you
can open configuration files and retrieve configuration sections from within
your application.

It gives Quick access to the appSettings and connectionStrings sections of
the current application's default configuration file, which you access
through properties such as AppSettings and ConnectionStrings

Note: The ASP.NET process account needs sufficient permissions to be able to
read and write into the specified configuration file.

For simplicity, to run the tryouts, enable Integrated Windows authentication
through IIS and enable impersonation at the Web site level using the
following configuration settings under the <system.web> element in the
web.config file.

<identity impersonate="true"/>

One of the Property = ConnectionStrings

This property gets the appropriate data from the <ConnectionStrings> section
of the current application's configuration file.


Retrieving Connection Strings
===================
..NET 2.0 introduces a new configuration section called <connectionStrings>
that lets you store connection strings securely in a .NET application.

These Steps will show you how to read the connection string that is stored
inside the <connectionStrings> section in a web.config file.

Step :1
--------------
First, you need to prepare your web.config file. For example, here's a
portion of a web.config that contains a <connectionString> entry.

<connectionStrings>

<add name="pubs"
connectionString="localhost;integrated
security=true;database=pubs;" />

</connectionStrings>

The following code retrieves that connection string from the web.config file
using the ConnectionStrings property of the ConfigurationManager class.

ConfigurationManager.ConnectionStrings["pubs"].ConnectionString

or

You can simply output the Connection String for example:

Response.Write("Connection String:"
+ ConfigurationManager. ConnectionStrings["pubs"].ConnectionString);

Bye
Venkat_KL
 
S

Scott Allen

It seems the book code wasn't updated from beta 1.

The easiest way to do this is to import System.WebConfiguration and
use:

Dim s As String =
WebConfigurationManager.ConnectionStrings("foo").ConnectionString
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top