1

我正在使用实体框架模型第一个 DAL 构建 ASP.NET Web 应用程序。我有两个 VS 项目:

  • 具有设计模型的类库
  • 一个 ASP.NET Web 应用程序。

在为我生成的类库 EF 中,以下连接字符串:

    <add name="DatabaseModelContainer" connectionString="metadata=res://*/DAL.DatabaseModel.csdl|res://*/DAL.DatabaseModel.ssdl|res://*/DAL.DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=NBK179\SQLEXPRESS;Initial Catalog=TaskBoardTest;Integrated Security=True;MultipleActiveResultSets=True&quot;"providerName="System.Data.EntityClient" />

它可以在类库项目中使用,但是当我将其粘贴到 Web 应用程序中并尝试将其与 EntityDataSource 一起使用时,会出现此错误:

[ArgumentException: Formato della stringa di inizializzazione non conforme alla specifica che inizia all'indice 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.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) +118
   System.Data.EntityClient.EntityConnection..ctor(String connectionString) +81
   System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString) +42
   System.Data.Objects.ObjectContext..ctor(String connectionString) +12
   System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +467
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +76
   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

我的代码:

Asp.net 页面:

<asp:EntityDataSource runat="server" 
ID="applicationDataSource" 
ConnectionString="DatabaseModelContainer" 
DefaultContainerName="DatabaseModelContainer" 
EnableFlattening="true" ></asp:EntityDataSource>

网页配置

<add name="DatabaseModelContainer" connectionString="metadata=res://*/DAL.DatabaseModel.csdl|res://*/DAL.DatabaseModel.ssdl|res://*/DAL.DatabaseModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=NBK179\SQLEXPRESS;Initial Catalog=TaskBoardTest;Integrated Security=True;MultipleActiveResultSets=True&quot;"providerName="System.Data.EntityClient" />

我怎么解决这个问题?提前致谢。

4

0 回答 0