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

regards,
MKItaniAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
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" ?>
<configuration>
    <connectionStrings>
        <add name="BITReports"
            connectionString="MY_CONNECTION_STRING"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>
0
 
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();
0
 
MKItaniAuthor Commented:
maybe he problem is in the dll "System.configuration" that i have added?
regards,
0
 
Paul JacksonConnect With a Mentor Software EngineerCommented:
Make sure it is the version for .net 2.0 framework
0
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.