我在Website上的Web.config中写了 <connectionStrings><add name ="LocalSqlServer" connectionString="server=.;Database =info;Uid = sa;Pwd =sa" /></connectionStrings>连接字符串我在工程中另外新建立一个类,,,应该怎样来从Web.config获取连接字符串
这是我新建的类
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DBsqlconn
{
/// <summary>
/// 数据库操作基本类
/// </summary>
public class SqlDataBase
{
//从Web.config获取连接字符串
private readonly string SqlConnectionString = //这后面怎么写哦
}
}谢谢拉
这是我新建的类
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DBsqlconn
{
/// <summary>
/// 数据库操作基本类
/// </summary>
public class SqlDataBase
{
//从Web.config获取连接字符串
private readonly string SqlConnectionString = //这后面怎么写哦
}
}谢谢拉
是什么原因拉我应用了
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;。
2003这样:System.Configuration.ConfigurationSettings.AppSettings["LocalSqlServer"].ToString();
private readonly string SqlConnectionString = ConfigurationSettings.AppSettings["LocalSqlServer"];
报错为:“ Error 1 #endregion directive expected ”
<configuration>
<appSettings>
<add key="SQLConnString"
value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA+aH2Q2KIrUydmSa/oXUuEwQAAAACAAAAAAADZgAAqAAAABAAAACX5Q/bTFwi5EnGrO7jJcA1AAAAAASAAACgAAAAEAAAAPS7B3MXVtc0+3nipIP6OHA4AAAAY40SKKPbe8JeyQt9NJLolnRX1eqGgEkeL0zy1Ubn8BNM2kgjKgwBPgtlARS27rBIzrREDd7pHqYUAAAAOpuMHp+1iNW7eQOaVCWAGtwGRXI=" />
</appSettings>
<configuration>
<appSettings>
<add key="DSN" value="servaer=.;uid=sa;pwd=sa;database=info"/>
</appSettings>
<configuration> 读取的时候用
String GetDSN = ConfigurationSettings.AppSettiings["DSN"];