tags:

views:

20

answers:

4
+2  A: 

You can use ConfigurationManager.ConnectionStrings to read the connection strings from the connection string section of your web.config file.

Or you can use ConfigurationManager.GetSection to get a section from the config file. If it is a predefined section you can cast it to this type, or you can implement your own custom section (see System.Configuration.ConfigurationSection for a sample).

Oh yes ... you have to include the System.Configuration into your references to work with these classes.

Obalix
+2  A: 

Why would you use SAX-based approach for reading configuration files? These are usually negligibly small, so loading entire document into an XmlDocument and then traversing it using XPath will be a much better solution.

Anton Gogolev
+1  A: 

Why try so hard?

Use this: ConfigurationManager.ConnectionStrings

Which is a collection of ConnectionStrings

Use ConfigurationManager.ConnectionStrings['nameOfTheConnectionString'].ConnectionString() to access the string itself.

ConfigurationManager lives in the System.Configuration namespace

Snake
+1  A: 

I can't tell what you're trying to do. But maybe XPath will be a lot easier than SAX.

SiN