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

I just upgraded my host to MVC 3 but I'm trying to do a "hello world" using SQLCE 4.0 but I just got:

Sorry, an error occurred while processing your request.

I see my layout and everything but instead of data I see that.

On localhost is working as expected

I have:

<add name="PruebaContext" connectionString="Data Source=|DataDirectory|db.sdf" providerName="System.Data.SqlServerCE.4.0"/>

as connectionString.

I put the sdf as part of the project, I added the System.Data.SqlServerCE.dll to the project with the local copy to true.

I have no more ideas. The connString, the dll is in /bin and is working in localhost.

Any ideas?

Thanks.

EDIT

I have some logs now:

Without the "System.Data.SqlServerCE.dll" on /bin:

Unable to find the requested .Net Framework Data Provider. It may not be installed.

System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

Fine enough. They don't have SqlServerCE4.

With the Dll on local copy, AKA /bin:

Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8482. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

Exception Details: System.Data.SqlServerCe.SqlCeException: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8482. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

The KB says that I need the dll from x86 and amd64. I read somewhere that if I copy two directories to /bin, like: /bin/x86 and /bin/amd64 . I copied that folders from the private folder of SqlServerCE 4 installation folder. Now I got:

Possible file version mismatch detected between ADO.NET Provider and native binaries of SQL Server Compact which could result in an incorrect functionality. This could be due to the presence of multiple instances of SQL Server Compact of different versions or due to wrong binaries with same name as SQL Server Compact binaries. Please install SQL Server Compact binaries of matching version.

Ok. On the root folder of SQLServerCE4 I have some dlls too, so I deleted that two folders and copied that dll to /bin:

Could not load file or assembly 'file:///C:\HostingSpaces\jesusrod\foxandxss.net\wwwroot\mvc3\bin\sqlceca40.dll' or one of its dependencies. The module was expected to contain an assembly manifest.

I think that I tried all things. Scottgu said that SqlServerCE 4 should work on any server without installation.

Answers


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.


Need Your Help

Drawing colored text in UIView's -drawRect: method

ios uikit drawrect uicolor nsattributedstring

I am trying to draw colored text in my UIView subclass. Right now I am using the Single View app template (for testing). There are no modifications except the drawRect: method.

RoR Getting Started Guide: Rake db:migrate undefined method 'reference'

ruby-on-rails rake dbmigrate

I'm following the RoR Getting Started tutorial. Having created posts, I'm now adding the second model to create comments. However, when I try rake db:migrate I get this: