10

I am using VS2012. I have to keep connection string in app.config and have to access it from my cs file. But I am unable to do it in VS2012. Following is what I have found from net but I think it works on earlier version of VS not on VS2012.

app.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
   <connectionStrings>
      <add name="DataFormConnection"
            connectionString="Data Source=abcdd;database=xyz;uid=4566;pwd=987"
            providerName="System.Data.SqlClient" />
   </connectionStrings>
</configuration>

How I am accessing it:

connectionString = ConfigurationManager.ConnectionStrings["DataFormConnection"].ConnectionString;

Getting error: type or name does not exist in System.Configuration.ConfiguarationSettings

2
  • Why is this tagged "ASP.Net"? Is it WPF or ASP.Net? 2-tier or 3-tier? app.config or web.config? Commented Apr 22, 2013 at 10:02
  • Your error message says System.Configuration.ConfigurationSettings but your code is using ConfigurationManager - can you clarify that you aren't using ConfigurationSettings somewhere (I think this class was .NET 1/1.1) Commented Apr 22, 2013 at 10:08

2 Answers 2

20

Go to references, and add a reference to System.Configuration.

Sign up to request clarification or add additional context in comments.

Comments

6

Go to References, and add a reference to System.Configuration

Once you have done this, you should be able to reference System.Configuration.ConfigurationManager.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.