Solved

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

Posted on 2011-09-30
4
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 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