Entity Framework6: 指定的架构无效

Entity Framework 6: Schema specified is not valid

我的解决方案中有 4 个以下项目。所有项目都使用目标框架版本 4.0。

SQL 服务器版本为2005。数据库CantorERP 和DuranetTest 都驻留在数据库服务器上。我从我的开发机器连接到数据库服务器。

在我的开发机器上一切正常。当我将 UI 项目部署到我们的托管服务器时(Windows 2003 SP2 运行ning IIS6 .net 版本 4.0)。我的 UI 项目中有以下三个页面(~/RAF/Common/NoChargeSearch.aspx~/RAF/Common/RAFSearch.aspx~RAF/Sales/CreateNoCharge.aspx)给我以下提到的错误。

Server Error in '/' Application.
Schema specified is not valid. Errors: 
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.MetadataException: Schema specified is not valid. Errors: 
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[MetadataException: Schema specified is not valid. Errors: 
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.]
   System.Data.Metadata.Edm.EdmItemCollection.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModelOption, DbProviderManifest providerManifest, ItemCollection itemCollection, Boolean throwOnError) +8617673
   System.Data.Metadata.Edm.EdmItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError) +139
   System.Data.Metadata.Edm.EdmItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) +158
   System.Data.Metadata.Edm.EdmMetadataEntry.LoadEdmItemCollection(MetadataArtifactLoader loader) +90
   System.Data.Metadata.Edm.EdmItemCollectionLoader.LoadItemCollection(EdmMetadataEntry entry) +12
   System.Data.Metadata.Edm.MetadataCache.LoadItemCollection(IItemCollectionLoader`1 itemCollectionLoader, T entry) +149
   System.Data.Metadata.Edm.MetadataCache.GetOrCreateEdmItemCollection(String cacheKey, MetadataArtifactLoader loader, Object& entryToken) +141
   System.Data.EntityClient.EntityConnection.LoadEdmItemCollection(MetadataWorkspace workspace, MetadataArtifactLoader artifactLoader) +103
   System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) +369
   System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() +29
   System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) +205
   System.Data.Objects.ObjectContext..ctor(String connectionString) +23
   System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +467
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +76
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +97
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +29
   System.Web.UI.Control.PreRenderRecursiveInternal() +103
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

项目中的所有其他页面都可以正常工作,包括相同目录中的页面,例如~/RAF/Common/NoCharge.aspx~/RAF/Common/RAF.aspx~RAF/Sales/CreateRAF.aspx。有趣的是,~/RAF/Common/RAFSearch.aspx 在一个名为 RAFSearch.cs 的 class 中使用了一个名为 GetTopNRafs() 的方法来在页面加载时显示数据,但它不起作用。另一个页面 ~/RAF/Sales/raf_pending_requests.aspx 在同一 class RAFSearch.cs 中使用 GetRafsByStatus() 方法在页面加载时显示数据并且它有效。这两种方法都使用 Durabuilt.Duranet2.Entities 项目和 return List<RAF>.

从 DuranetTest DB 获取数据

我已确保我的 Entities 项目和 UI 项目具有相同版本的 EntityFramework(版本 6.1.3)。

我尝试在 Durabuilt.CantorERP.Entities 和 Durabuilt.Duranet2.Entities 项目中删除并重新创建 .edmx 文件。我尝试从 edmx 中删除所有表和视图并使用 "update model from Database" 选项并重新添加表和视图。我还删除并重新创建了 Durabuilt.CantorERP.Entities 和 Durabuilt.Duranet2.Entities 项目。不确定我是否遗漏了任何关键信息。如果需要其他信息,请告诉我,我可以根据要求添加信息。

我阅读了各种有类似问题的文章,将服务器升级到 .net 版本 4.5 似乎解决了问题。但我目前没有升级 .net 版本的选项,也无法在服务器上安装 SP3,因为它正在 运行 宁其他一些可能会中断的应用程序。请让我知道如何解决此错误。感谢您的帮助。

请求的连接字符串:

<connectionStrings>
   <add name="CANTORERPConnectionString" connectionString="Data Source=CANTORSERVER;Initial Catalog=CANTORERP;Integrated Security=False; User Id=XXXXXX; password=XXXXXX" providerName="System.Data.SqlClient" />
   <add name="CantorERPEntities" connectionString="metadata=res://*/CantorERPModel.csdl|res://*/CantorERPModel.ssdl|res://*/CantorERPModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CANTORSERVER;initial catalog=CANTORERP;persist security info=True;user id=XXXXXX;password=XXXXXX;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   <add name="DURANET2Entities" connectionString="metadata=res://*/Duranet2Model.csdl|res://*/Duranet2Model.ssdl|res://*/Duranet2Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CANTORSERVER;initial catalog=DURANETTEST;persist security info=True;user id=XXXXXX;password=XXXXXX;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

我使用 CANTORERPConnectionString 来 运行 直接对数据库进行 SQL 查询。 CantorERPEntitiesDURANET2Entities 都是 Entities 项目使用的连接字符串。

好的,这就是为我解决的问题。发布这个,因为它可以帮助其他可能 运行 陷入同样错误的人。

这三个页面(页面加载时出现此错误)具有下拉控件。这些下拉控件中的每一个都使用实体数据源绑定到数据库 table,如下所示:

<asp:DropDownList ID="ddlStatus" runat="server" DataSourceID="EDS_Status" DataTextField="Status" DataValueField="Id"></asp:DropDownList>
<asp:EntityDataSource runat="server" ID="EDS_Status" DefaultContainerName="DURANET2Entities" ConnectionString="name=DURANET2Entities" EnableFlattening="False" EntitySetName="RAFStatuses" Select="it.[Id], it.[Status]"></asp:EntityDataSource>

这就是导致我的错误的原因。以某种方式在控件绑定时在页面加载时生成此错误。这适用于开发环境,但会导致服务器(Windows 2003 SP2、IIS6、.NET Framework 4.0)出现错误,这就是难以排除故障的原因。

只需将数据源更改为SQL数据源,问题就解决了。像这样:

asp:DropDownList ID="ddlStatus" runat="server" DataSourceID="SqlDataSource1" DataTextField="Status" DataValueField="Id"></asp:DropDownList>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:DURANETConnectionString %>' SelectCommand="SELECT [Id], [Status] FROM [RAFStatuses] ORDER BY [Id]"></asp:SqlDataSource>

如果有人需要更多详细信息,请告诉我。