The name 'ConfigurationManager' does not exist in the current context

問題:

I am trying to access connectionStrings from the config file.我正在嘗試從配置文件訪問connectionStrings The code is ASP.NET + C#.代碼是 ASP.NET + C#。 I have added System.Configuration to reference and also mentioned with using.我已經添加了System.Configuration以供參考,並且還提到了使用。 But still it wouldn't accept the assembly.但它仍然不會接受程序集。

I am using VSTS 2008. Any idea what could be the reason?我正在使用 VSTS 2008。知道是什麼原因嗎?

Another weird thing is the assembly name shown as "System.configuration", a lower case c which is not how names are displayed for other System assemblies.另一個奇怪的事情是程序集名稱顯示爲“System.configuration”,一個小寫的 c 這不是其他系統程序集的名稱顯示方式。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Utility
{
    public class CommonVariables
    {
        public static String ConnectionString
        {
            get { return ConfigurationManager.ConnectionStrings["EmployeeEntities"].ConnectionString; }
        }  
    }  
}

Config:配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="qbankEntities" connectionString="metadata=res://*/qbankModel.csdl|res://*/qbankModel.ssdl|res://*/qbankModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost;Initial Catalog=qbank;Persist Security Info=True;User ID=**;Password=****;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

解決方案:

參考一: https://en.stackoom.com/question/5Le8
參考二: https://stackoom.com/question/5Le8
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章