初始化字符串的格式不符合从索引0开始不起作用的规范

时间:2012-06-27 22:01:51

标签: asp.net sql-server

我已经阅读了有关此问题的所有主题,但未找到任何问题的答案。我试过不同的连接字符串而没有运气?

我尝试过很多东西,但我不知道是什么原因造成的?有没有人有同样的问题并找到了解决方案?

首先是我的堆栈跟踪

堆栈追踪:

[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
 System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +5081160
 System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +132
 System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +98
 System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +64
 System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
 System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +150
 System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +59
 System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
 System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +34
 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +117
 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
 System.Web.UI.WebControls.GridView.DataBind() +4
 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
 System.Web.UI.Control.EnsureChildControls() +102
 System.Web.UI.Control.PreRenderRecursiveInternal() +42
 System.Web.UI.Control.PreRenderRecursiveInternal() +175
 System.Web.UI.Control.PreRenderRecursiveInternal() +175
 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

WEB CONFIG

  <connectionStrings>
  <add name="riktigaconnstringen" connectionString="Data Source=aspx-XXXXX.mssql.binero.se;Initial Catalog=XXXX-aspx;Persist Security Info=True;User ID=XXXX;Password=XXXXX"/>

和我的页面

 <asp:SqlDataSource 
        ID="test1" 
        runat="server" 
        DataSourceMode="DataSet"
        SelectCommand="SELECT * FROM t_produkter"
        ConnectionString="<% ConnectionStrings:riktigaconnstringen %>"></asp:SqlDataSource>
 </connectionStrings>

1 个答案:

答案 0 :(得分:2)

我不确定这是否是导致问题的原因,但在SqlDataSource的MSDN示例中,我可以看到用于引用ConnectionString的不同语法

  <asp:SqlDataSource
      ID="test1"   
      runat="server"   
      DataSourceMode="DataSet"  
      SelectCommand="SELECT * FROM t_produkter"  
      ConnectionString="<%$ ConnectionStrings:riktigaconnstringen %>"></asp:SqlDataSource
  </asp:SqlDataSource>

请注意$

后的<%字符