ASP.NET连接字符串错误

时间:2014-02-13 10:45:00

标签: c# asp.net sql-server-2008-r2 connection-string

我有一个看起来像

的Sql Server 2008 R2连接字符串
  <add name="DBConnectionString"
Data Source=XXXX;uid=rp1;pwd=XXXX;Initial Catalog=XXX;"/>

尝试使用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 :(得分:2)

添加

providerName="System.Data.SqlClient"
连接字符串

中的