连接字符串的Base-64字符串中的字符无效

时间:2014-02-11 04:31:09

标签: asp.net ado.net enterprise-library

我有一个看起来像

的Sql Server 2008 R2连接字符串
  <add name="DBConnectionString"
providerName="System.Data.SqlClient"
connectionString="Data Source=AYZ;Initial Catalog=AYZ;User ID=AYZ;Password=AYZ;"/>

尝试使用EnterpriseLibrary.Data创建新的SQLDatabase实例时出现上述错误。

connString =ConnectionStrings.ConnectionStrings["DBConnectionString"];
Database objDB = new SqlDatabase(connString);

connString具有以下内容

Data Source=AYZ;Initial Catalog=AYZ;User ID=AYZ;Password=AYZ;

详细例外情况如下:

System.FormatException was unhandled by user code
  Message=Invalid character in a Base-64 string.
  Source=mscorlib
  StackTrace:
       at System.Convert.FromBase64String(String s)
       at Microsoft.Practices.EnterpriseLibrary.Data.Database.DecryptConnectionString(String strEncyptConStr)
       at Microsoft.Practices.EnterpriseLibrary.Data.Database..ctor(String connectionString, DbProviderFactory dbProviderFactory)
       at Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase..ctor(String connectionString)
       at ABC.GRC.DAL.CommonDAL..ctor() in D:\ABC\Projects\Right Price\ABC.GRC\ABC.GRC\ABC.GRC.DAL\CommonDAL.cs:line 31
       at ABC.GRC.BLL.CommonBLL..ctor() in D:\ABC\Projects\Right Price\Syntel.GRC\Syntel.GRC\Syntel.GRC.BLL\CommonBLL.cs:line 14
       at Global.Application_Error(Object sender, EventArgs e) in d:\ABC\Projects\Right Price\ABC.GRC\ABC.GRC\ABC.GRC.WEB\App_Code\Global.asax.cs:line 60
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Web.HttpApplication.RaiseOnError()
  InnerException: 

1 个答案:

答案 0 :(得分:0)

我认为存在问题

connString =ConnectionStrings.ConnectionStrings["ConnectionString"];

应该是

connString =ConnectionStrings.ConnectionStrings["DBConnectionString"];

由于配置文件中的密钥DBConnectionString不是ConnectionString

有用的链接:

  1. Read connection string from web.config