2015-05-11 39 views
0

我的解決方案中有4個以下項目。所有的項目都使用目標框架版本4.0。實體框架6:指定的模式無效

  • 1. Durabuilt.CantorERP.Entities>類庫項目>使用ADO.NET實體數據模型暴露在名爲CantorERP
  • 2. Durabuilt.Duranet2.Entities SQL數據庫>類庫項目>使用ADO.NET實體數據模型表和視圖暴露在SQL表名爲DuranetTest的數據庫
  • 3. Durabuilt.Duranet2.BL>類庫項目>包含業務邏輯並引用上述兩個用於CRUD操作的實體項目。包括CRUD在內的所有邏輯都駐留在此項目中。
  • 4. Durabuilt.Duranet2.UI>這是一個網站,它是UI和參考Durabuilt.Duranet2.BL項目。

SQL Server版本是2005.數據庫CantorERP和DuranetTest都駐留在數據庫服務器上。我從我的開發機器連接到數據庫服務器。

一切工作正常我的開發機器上。當我將UI項目部署到我們的託管服務器(Windows 2003 SP2運行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的類中使用名爲GetTopNRafs()的方法來顯示頁面加載數據,但不起作用。另一頁~/RAF/Sales/raf_pending_requests.aspx使用GetRafsByStatus()同一類RAFSearch.cs中的方法來顯示頁面加載數據,它的工作原理。兩種方法都使用Durabuilt.Duranet2.Entities項目從DuranetTest數據庫獲取數據並返回List<RAF>

我確定我的實體項目和UI項目都具有相同版本的EntityFramework(版本6.1.3)。

我試過在Durabuilt.CantorERP.Entities和Durabuilt.Duranet2.Entities項目中刪除並重新創建.edmx文件。我試過從edmx刪除所有表和視圖,並使用「從數據庫更新模型」選項並重新添加表和視圖。我也刪除並重新創建了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都是實體項目使用的連接字符串。

+0

你能顯示你的連接字符串嗎? – nZeus

+0

此命名空間:'http:// schemas.microsoft.com/ado/2009/11/edm'指示在.NET Framework 4上不支持的EDM v3。 – Pawel

+0

@nZeus添加了連接字符串。 –

回答

-1

好吧,這是什麼解決它對我來說。發佈此信息可以幫助其他可能遇到相同錯誤的人。

這三個頁面(頁面加載時出現此錯誤)已經下拉控件。每一種下拉控件被綁定到使用實體數據源,像這樣一個數據庫表:

<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> 

讓我知道是否有人需要額外的細節。