当前上下文中不存在名称“ConfigurationManager" [英] The name 'ConfigurationManager' does not exist in the current context

查看:18
本文介绍了当前上下文中不存在名称“ConfigurationManager"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从配置文件访问 connectionStrings.代码是 ASP.NET + C#.我已经添加了 System.Configuration 以供参考,并且还提到了 using.但它仍然不会接受程序集.

I am trying to access connectionStrings from the config file. The code is ASP.NET + C#. I have added System.Configuration to reference and also mentioned with using. But still it wouldn't accept the assembly.

我使用的是 VSTS 2008.知道是什么原因吗?

I am using VSTS 2008. Any idea what could be the reason?

另一个奇怪的事情是程序集名称显示为System.configuration",一个小写的 c 这不是其他系统程序集的名称显示方式.

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.

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; }
        }  
    }  
}

配置:

<?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>

推荐答案

好的.. 重启 VSTS 后就可以了.链接建议相同问题的解决方案.希望我以前能看到它.:)

Ok.. it worked after restarting the VSTS. The link suggested the solution for the same problem. Wish i could have seen it before. :)

这篇关于当前上下文中不存在名称“ConfigurationManager"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆