在web.config中配置如下:
<connectionStrings>
  <add name="SQLConnectionString" connectionString="Data Source=localhost\\SQLEXPRESS; Database=CMS;User Id=sa; Pwd=123456" providerName="System.Data.SqlClient"/>
</connectionStrings>
在代码文件中获取连接串如下:
string constring = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;
查看了很多说法,都是这样做的。但是我这样写constring值为空,编译的时候也说“实例失败”,错误信息见下:-------------------------------------------------------------------------------------------------------------
实例失败。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 实例失败。源错误: 行 33:                 SqlConnection conn = new SqlConnection(constring);
行 34:                 conn.Open();
行 35:                 string selectstr = "select user_power from users where user_name='" + UserName.Text + "'and user_password='" + UserPassword.Text + "'";
行 36:                 SqlCommand logoncom = new SqlCommand(selectstr, conn);
------------------------------------------------------------------------------------------------------------- 取消web.config配置,该改到代码文件中直接使用"Data Source=localhost\\SQLEXPRESS; Database=CMS;User Id=sa; Pwd=123456"连接数据库正常。究竟是什么原因呢?百思不得其解,请高人指点!不胜感激!