Question

I am working on a ASP.NET Web Pages site with SQL Server CE 4.0.

I believe my SQL Server CE 4.0 database is working fine. I can connect to it without any problems on my dev machine with and without Entity Framework.

Once I push the site to the server, I can connect to it fine without entity framework using this connection string:

<add name="StarterSite" 
     connectionString="Data Source=|DataDirectory|\StarterSite.sdf" 
     providerName="System.Data.SqlServerCe.4.0" />

My Entity Framework connection string looks like this:

<add name="StarterSiteEntities" 
     connectionString="metadata=res://*/App_Code.ProductModel.csdl|res://*/App_Code.ProductModel.ssdl|res://*/App_Code.ProductModel.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=|DataDirectory|\StarterSite.sdf&quot;" 
     providerName="System.Data.EntityClient" />

When I try to make any EF database calls I get this error message:

Server Error in '/' Application.

Schema specified is not valid.

Errors:
App_Code.ProductModel.ssdl(2,88) : error 0004: Could not load System.Data.SqlServerCe.Entity.dll. Reinstall SQL Server Compact.

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:
App_Code.ProductModel.ssdl(2,88) : error 0004: Could not load System.Data.SqlServerCe.Entity.dll. Reinstall SQL Server Compact.

Source Error:

Line 23: using (var db = new StarterSiteEntities())
Line 24: {
Line 25: product = (from p in db.Products
Line 26: where p.ProductID == productId
Line 27: select p).FirstOrDefault();

Source File: c:\sites\www.foosite.org\Admin-RUF\Admin-Product-Edit.cshtml Line: 25

Stack Trace:

[MetadataException: Schema specified is not valid. Errors: App_Code.ProductModel.ssdl(2,88) : error 0004: Could not load System.Data.SqlServerCe.Entity.dll. Reinstall SQL Server Compact. ] System.Data.Metadata.Edm.Loader.ThrowOnNonWarningErrors() +8610213 System.Data.Metadata.Edm.Loader.LoadItems(IEnumerable1 xmlReaders, IEnumerable1 sourceFilePaths) +189 System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable1 xmlReaders, IEnumerable1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer2& cachedCTypeFunction) +182 System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable1 xmlReaders, IEnumerable1 filePaths) +244 System.Data.Metadata.Edm.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader) +90 System.Data.Metadata.Edm.StoreItemCollectionLoader.LoadItemCollection(StoreMetadataEntry entry) +16 System.Data.Metadata.Edm.MetadataCache.LoadItemCollection(IItemCollectionLoader1 itemCollectionLoader, T entry) +163 System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken) +191 System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader) +246 System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) +586 System.Data.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure) +75 System.Data.EntityClient.EntityConnection.Open() +150 System.Data.Objects.ObjectContext.EnsureConnection() +75 System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) +41 System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +36 System.Linq.Enumerable.FirstOrDefault(IEnumerable1 source) +152 System.Data.Objects.ELinq.ObjectQueryProvider.b__1(IEnumerable1 sequence) +41 System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable1 query, Expression queryRoot) +59 System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +133 System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +87 System.Linq.Queryable.FirstOrDefault(IQueryable1 source) +251 ASP._Page_admin_ruf_Admin_Product_Edit_cshtml.Execute() in c:\sites\www.foosite.org\Admin-RUF\Admin-Product-Edit.cshtml:25 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +198 System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable1 executors) +69 System.Web.WebPages.WebPage.ExecutePageHierarchy() +131 System.Web.WebPages.StartPage.RunPage() +17 System.Web.WebPages.StartPage.ExecutePageHierarchy() +64 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78 System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +116

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18044


What am I doing wrong?

Was it helpful?

Solution

Deploy System.Data.SqlServerCe.Entity.dll with your app, It is in C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.Entity on my PC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top