【问题标题】:Need Help in connection string在连接字符串中需要帮助
【发布时间】:2015-08-02 14:10:33
【问题描述】:
<connectionStrings>
  <add name="mycollegeproject" connectionString="Data Source=mssql2.gear.host;Initial Catalog=mycollegeproject;Persist Security Info=True;User ID=mycollegeproject;Password=*******" />
</connectionStrings>

public static string strcon = ConfigurationManager.ConnectionStrings["mycollegeproject"].ConnectionString;

还有错误

System.NullReferenceException: Object reference not set to an instance of an object.

【问题讨论】:

标签: c# asp.net web-config connection


【解决方案1】:

如果没有错,大多数情况下您没有在名为 mycollegeprojectApp.config 中定义连接字符串(或者)您在代码中使用了不同的键名而不是使用 mycollegeproject,因此下面的代码行返回 @ 987654324@ 导致 NRE。

ConfigurationManager.ConnectionStrings["mycollegeproject"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多