Using SQL Server CE 4 on a remote host with MVC 3

此生再无相见时 提交于 2019-11-27 18:22:14

I don't like to respond to my own answer, but after hours of work I have the answer!

We need:

NuGet (Better than copying the dll's from program file)

With NuGet we install:

EFCodeFirst

SqlServerCompact

EFCodeFirst.SqlServerCompact

The problem was that EF need another dll for SQL CE 4 (System.Data.SqlServerCe.Entity.dll) and we need to put some configuration on web.config:

  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

With that, all is working. I have seen like 5 different errors, so we need:

The 2 dll from SQL CE 4, the EF dll, the config in web.config and the native dll (from the package directory where NuGet downloads the library).

It seems that the web.config config is pointing to a concrete version of the SQL CE .dll and the version of the RTM package is different. I can't find the concrete version so I use the .dll from NuGet.

That's all, SQL CE 4 + EF on a remote host.

Just use menu "Project/Add Deployable Dependencies..." I'm not sure if it is Visual Studio 2010 SP 1 only.

You need to make sure you have the native SQL CE 4.0 dlls in your private application directory (e.g. \bin) in addition to the managed one.

Copy them from "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private\amd64" (or x86 if you have a 32-bit app).

It may also be wise to deploy the MSVCR90.dll and it's manifest too. Have a look at the documentation in C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0 for more information about the required DLLs and redistribution.

This looks like a problem that's caused by having multiple intermediate bits of data left in a project, where you've replaced included files without cleaning up.

I'd recommend doing a Build->Clean all, followed by making sure that all of your references are to the new, correct DLLs, and then making sure that none of the old files or references are still around anywhere in your project. Attempt to rebuild once that is done.

Since this is a hello world project, it might be easier to just start from scratch with a new project, and include the correct dlls in there.

try installing SQL CE manually.

http://www.microsoft.com/download/en/details.aspx?id=17876

Good Luck.

I was having the same problem. Trying to put a code-first SQL CE 4.0 app into play on my goDaddy account.

I started messing around with various DLL files based upon the thread above and other tutorials, but nothing seemed to work. Something was missing. Then I read about the Add Deployable Dependencies response.

I did that, which created _bin_deployableAssemblies folder. Then I deleted everything from my bin folder except my core project's DLL and copied everything from _bin_deployableAssemblies into the bin folder.

I cleaned out everything in the bin folder on my goDaddy app and resynced the files. That worked. The app loads and if I make codefirst changes to the classes, the dbcontext recreates the database for me. Of course, I don't want that in production, but I wanted to know that everything was working.

I did try using the ASP tutorial about deploying an MVC app to a hosting environment (they use Cytanium hosting as their example), but it didn't work for me on GoDaddy. I had to copy files manually.

Thanks all. This was a huge step for me being able to feel comfortable continuing in MVC and EF.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!