简体   繁体   English

对象未设置为对象的实例

[英]Object not set to an instance of object

I have the following connection string in the web.config file, when I run I get an error 我在web.config文件中有以下连接字符串,运行时出现错误

"Object not set to an instance of object" “对象未设置为对象的实例”

at the following line. 在下一行。 I am using sql server 2012 db and visual studio 2010. 我正在使用SQL Server 2012数据库和Visual Studio 2010。

dbConnectionString = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;

Config 配置

<connectionStrings>
<add name="myConnection" connectionString="Data Source=sag-pc\;Initial Catalog=BalloonShop;Persist Security Info=True;User ID=sa;Password=pwd" providerName="System.Data.SqlClient" />

Try this 尝试这个

Config : 配置:

  <appSettings>
<add key="myConnection" value="Data Source=sag-pc;Initial Catalog=BalloonShop;Persist Security Info=True;User ID=sa;Password=pwd;providerName=System.Data.SqlClient"/>
  </appSettings>

In Code : 在代码中:

string _connection=ConfigurationManager.AppSettings["myConnection"].ToString(); 字符串_connection = ConfigurationManager.AppSettings [“ myConnection”]。ToString();

请尝试以下操作:

ConfigurationManager.ConnectionStrings["myConnection"].ToString()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM