ConnectionString 是NULL 如何解决
动软里面 public class PubConstant{
/// <summary>
/// 获取连接字符串
/// </summary>
public static string ConnectionString
{
get
{
string _connectionString = ConfigurationManager.AppSettings["ConnectionString"];
string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
if (ConStringEncrypt == "true")
{
_connectionString = DESEncrypt.Decrypt(_connectionString);
}
return _connectionString;
}
}
/// <summary>
/// 得到web.config里配置项的数据库连接字符串。
/// </summary>
/// <param name="configName"></param>
/// <returns></returns>
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;
}
}
然后我用
PubConstant.GetConnectionString("workstation id=localhost;Integrated Security=SSPI;database=zbroad2009");
MessageBox.Show(PubConstant.ConnectionString);
结果发现.ConnectionString 是NULL
是空的
这个Connectionstring 如何赋值呢