问题:
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="Data Source=localhost;Initial Catalog=qbank;Persist Security Info=True;User ID=**;Password=****;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
解决方案:
参考一: https://en.stackoom.com/question/5Le8参考二: https://stackoom.com/question/5Le8