首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >实体框架6:指定的架构无效

实体框架6:指定的架构无效
EN

Stack Overflow用户
提问于 2015-05-11 22:00:32
回答 1查看 2.7K关注 0票数 0

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

  • 1. Durabuilt.CantorERP.Entities >类库项目>使用ADO.NET实体数据模型公开CantorERP数据库中的表和视图
  • 2. Durabuilt.Duranet2.Entities >类库项目>使用ADO.NET实体数据模型在DuranetTest数据库中公开表
  • 3. Durabuilt.Duranet2.BL >类库项目>包含用于CRUD操作的上述两个实体项目的业务逻辑和引用。包括CRUD在内的所有逻辑都驻留在这个项目中。
  • 4. Durabuilt.Duranet2.UI >它是一个网站,它是用户界面,并引用了Durabilt.Duranet2.BL项目。

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

在我的开发机器上一切正常。当我将UI项目部署到我们的主机服务器(Windows2003运行SP2 IIS6 .net Version4.0)时。在我的UI项目中,有三个页面(~/RAF/Common/NoChargeSearch.aspx~/RAF/Common/RAFSearch.aspx~RAF/Sales/CreateNoCharge.aspx)给我带来了下面提到的错误。

代码语言:javascript
复制
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的类中使用了一个名为GetTopNRafs()的方法来在页面加载时显示数据,但它不起作用。另一个页面~/RAF/Sales/raf_pending_requests.aspx使用同一类RAFSearch.cs中的GetRafsByStatus()方法来显示页面加载上的数据,并且它可以工作。这两种方法都使用Durabilt.Duranet2.Entities项目从DuranetTest DB获取数据,并返回List<RAF>

我已经确保我的实体项目和UI项目都有相同版本的EntityFramework (版本6.1.3)。

我尝试移除和重新创建.edmx文件中的Durabuilt.CantorERP.Entities和Durabilt.Duranet2.Entities项目。我尝试过从edmx删除所有表和视图,并使用了“从数据库更新模型”选项和重新添加的表和视图。我还删除并重新创建了Durabuilt.CantorERP.Entities和Durabilt.Duranet2.Entities项目。不知道我是不是漏掉了任何重要信息。如果需要更多的信息,请让我知道,我可以根据要求添加信息。

我阅读过一些类似问题的文章,并将服务器升级到.net版本4.5似乎解决了这个问题。但是,我目前没有升级.net版本的选项,也无法在服务器上安装SP3,因为它正在运行一些可能中断的其他应用程序。请让我知道可以做些什么来纠正这个错误。感谢你的帮助。

请求的连接字符串:

代码语言:javascript
复制
<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对DB运行直接的SQL查询。CantorERPEntitiesDURANET2Entities都是实体项目使用的连接字符串。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-12 22:24:58

好的,这就是为我解决这个问题的原因。发布这篇文章,因为它可以帮助其他可能遇到同样错误的人。

三个页面(在页面加载时出现了此错误)已经放下了控件。每个下拉控件都使用实体数据源绑定到数据库表,如下所示:

代码语言:javascript
复制
<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>

在我的情况下,这就是导致错误的原因。当控件被绑定时,不知何故在页面加载中,就会生成此错误。这在dev环境中有效,但会导致服务器上的错误(Windows2003SP2、IIS6、.NET Framework4.0),这就是为什么很难排除故障的原因。

仅仅通过将数据源更改为SQL数据源,问题就得到了解决。就像这样:

代码语言:javascript
复制
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>

如果有人需要更多的细节,请告诉我。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30178345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档