Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have tried 1 and 2 but not working

1.private string constring = ConfigurationSettings.AppSettings["constring"].ToString();
2.private string constring=ConfigurationManager.ConnectionStrings["constring"].ConnectionString;

connection strting problem.
ERROR message=Object reference not set to an instance of an object

Gaurang R.
Posted
Comments
Prabhakaran Soundarapandian 17-Aug-12 6:39am    
In your solution how many project you are using and in which project you are using this code and which is your startup project?

You need to learn to use a debugger. This error means what it says. constring is not a value in your connection strings or configuration settings. If it was, it would not need ToString called on it, it should be a string.
 
Share this answer
 
If you having multiple project in your solution, and say the startup project is webapplication and you having the below code

C#
<connectionstring>
<add name="" mode="hold" /></connectionstring>


in Data Access Layer (DAL)[class library project] configuration file means that doesn't make any sense you have to add that in startup project say here as webapplication's web.config file.
 
Share this answer
 
i have solved.


have to Add reference-> .net-> System.Configuration

add reference again if you have added using system.configuration

then
private string constring = ConfigurationManager.ConnectionStrings["constring"].ConnectionString;

it will work properly

Gaurang R.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900