你调用的对象是空的.连接概率. [英] Object reference not set to an instance of an object. connection prob.
问题描述
我尝试了1和2,但没有工作
1.private string constring = ConfigurationSettings.AppSettings ["constring"].ToString();
2.private string constring = ConfigurationManager.ConnectionStrings ["constring"].ConnectionString;
连接问题.
错误消息=对象引用未设置为对象的实例
Gaurang R.
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.
推荐答案
您需要学习使用调试器.此错误表示它的意思. constring不是您的连接字符串或配置设置中的值.如果是这样,则不需要在其上调用ToString,它应该是一个字符串.
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.
如果您的解决方案中有多个项目,并说启动项目是web应用程序,并且您拥有下面的代码
If you having multiple project in your solution, and say the startup project is webapplication and you having the below code
<connectionstring>
<add name="" mode="hold" /></connectionstring>
数据访问层(DAL)[类库项目]配置文件中的文件意味着没有任何意义,您不必在启动项目中将其添加为web应用程序的web.config文件.
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.
我解决了.
必须添加参考-> .net-> System.Configuration
如果已使用system.configuration添加,请再次添加参考
然后
私有字符串constring = ConfigurationManager.ConnectionStrings ["constring"].ConnectionString;
它会正常工作
高朗河.
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.
这篇关于你调用的对象是空的.连接概率.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!