Connection string+App.config+visual studio 2008+window application

Hi All,
I am trying this code a lot of times in the past without any problem
but now i have created a new project in c# then i added the dll from .net (System.configuration) throw add reference.
but i get this error at run time
"Object reference not set to an instance of an object."
there is my code:
String connectString = System.Configuration.ConfigurationManager.ConnectionStrings["BITReports"].ConnectionString;

i don't know what is the problem maybe i missed somethink

Who is Participating?

Improve company productivity with a Business Account.Sign Up

Carlos VillegasConnect With a Mentor Full Stack .NET DeveloperCommented:
Hello, be sure that your app.config contains the correct entry, example (simplified):
<?xml version="1.0" encoding="utf-8" ?>
        <add name="BITReports"
            providerName="System.Data.SqlClient" />
Paul JacksonConnect With a Mentor Software EngineerCommented:
Are you sure you are using the correct name?
try adding .ToString to the end :
String connectString = System.Configuration.ConfigurationManager.ConnectionStrings["BITReports"].ConnectionString.ToString();
MKItaniAuthor Commented:
maybe he problem is in the dll "System.configuration" that i have added?
Paul JacksonConnect With a Mentor Software EngineerCommented:
Make sure it is the version for .net 2.0 framework
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.