How to read from ap.config

A

ad

I have stored my connectionstring in ap.config like:
<configuration>
<appSettings/>
<section name="microsoft.visualstudio.testtools"
type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection,
Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<connectionStrings>
<add name="myDataBase" connectionString="Data Source=.\;Initial
Catalog=SchoolGov;Integrated Security=True" />
</connectionStrings>
</configuration>

How can I read it into application?
 
G

Guest

Add your connection strings to the appSettings section rather than creating a
custom section like this:

<appSettings>
<add key="myDataBase" value="Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=northwind" />
</appSettings>

Then, to get the value, use:

string connectionstring =
System.Configuration.ConfigurationSettings.AppSettings["myDataBase"];


If you are determined to use a custom section for your connection strings, I
suggest starting with this article from Chris Sells:

http://www.sellsbrothers.com/askthewonk/secure/default.aspx?content=whatsthebestwaytomaintain.htm

HTH

Dale Preston
MCAD C#
MCSE, MCDBA
 

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

Top