Base-64字符串中的无效字符“使用ASP.NET

时间:2014-02-10 16:34:57

标签: asp.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["ConnectionString"];
Database objDB = new SqlDatabase(connString);

详细例外情况如下:

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 Syntel.GRC.DAL.CommonDAL..ctor() in D:\Vrushal\Projects\Right Price\Syntel.GRC\Syntel.GRC\Syntel.GRC.DAL\CommonDAL.cs:line 31
       at Syntel.GRC.BLL.CommonBLL..ctor() in D:\Vrushal\Projects\Right Price\Syntel.GRC\Syntel.GRC\Syntel.GRC.BLL\CommonBLL.cs:line 14
       at Global.Application_Error(Object sender, EventArgs e) in d:\Vrushal\Projects\Right Price\Syntel.GRC\Syntel.GRC\Syntel.GRC.WEB\App_Code\Global.asax.cs:line 60
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Web.HttpApplication.RaiseOnError()
  InnerException: 

请帮我解决一下。

感谢。

2 个答案:

答案 0 :(得分:1)

您在连接字符串属性的末尾缺少"。它应该是:

<add name="ConnectionStringName"
    providerName="System.Data.SqlClient"
    connectionString="Data Source=ServerName\InstanceName;Initial Catalog=DatabaseName;"/>

答案 1 :(得分:0)

连接字符串必须加密才能工作。负责该项目的团队使用base64encode.org对字符串进行编码。