日期:2014-05-17  浏览次数:20845 次

动软的 public class PubConstant 如何解决。
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;
  }


  }
}
然后呢,我用以下方式赋值
private void Form1_Load(object sender, EventArgs e)
  {
  PubConstant.GetConnectionString("workstation id=localhost;Integrated Security=SSPI;database=caiwubook");
   
  }
结果就报错了
帮我看一下错在那里。

------解决方案--------------------
什么错误?哪行错误?IDE没有告诉你吗?
------解决方案--------------------
应该是下面这样的:
PubConstant.GetConnectionString("MyConfig");

------解决方案--------------------
检查config中是否配置
ConnectionString
------解决方案--------------------
PubConstant.GetConnectionString(configName)