Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

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,
0
MKItani
Asked:
MKItani
  • 2
3 Solutions
 
Paul JacksonCommented:
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
 
Carlos VillegasFull 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
 
MKItaniAuthor Commented:
maybe he problem is in the dll "System.configuration" that i have added?
regards,
0
 
Paul JacksonCommented:
Make sure it is the version for .net 2.0 framework
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now