Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

asp.net mvc 3 - 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:HostingSpacesjesusrodfoxandxss.netwwwrootmvc3insqlceca40.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...