properties连接sql数据库用windows身份进入怎么写?

2024-11-30 07:45:07
推荐回答(1个)
回答1:

好心人帮帮忙吧···
方法一:

获得webconfig中的连接语句
///


/// 获取连接字符串
///

public static string ConnectionString
{
get
{
string _connectionString = ConfigurationManager.AppSettings["ConnectionString"];
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
_connectionString = DESEncrypt.Decrypt(_connectionString);
}
return _connectionString;
}
}

///
/// 得到web.config里配置项的数据库连接字符串。
///

///
///
public static string GetConnectionString(string configName)
{
string connectionString = ConfigurationManager.AppSettings[configName];
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
connectionString = DESEncrypt.Decrypt(connectionString);
}
return connectionString;
}

webconfig







类中的方法你懂的
//数据库连接字符串(web.config来配置),可以动态更改connectionString支持多数据库.
public static string connectionString = PubConstant.ConnectionString;

看完了 别忘了给我加分