Solved

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

Posted on 2011-09-30
4
232 Views
Last Modified: 2012-05-12
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
Comment
Question by:MKItani
  • 2
4 Comments
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 200 total points
ID: 36892764
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
 
LVL 17

Accepted Solution

by:
Carlos Villegas earned 300 total points
ID: 36892792
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
 

Author Comment

by:MKItani
ID: 36896172
maybe he problem is in the dll "System.configuration" that i have added?
regards,
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 200 total points
ID: 36896234
Make sure it is the version for .net 2.0 framework
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now