Installing SQL Server Compact Edition 3.5 SP2 with ADO.NET Entity Framework locally

2 09 2010

When using SQL Server CE as a local database engine the SQL Server CE components need to be installed locally. This could easily be done using the SQL Server CE setup package provided by Microsoft. But this requires the end user to manually install the SQL Server CE .msi as a prerequisite component.

As an alternative one could create a setup bootstrapper to include and automatically run the SQL Server CE installer during setup of the custom application. But this requires additional development effort.

What I wanted was to completely include the SQL Server CE runtime components with the setup installer of my application. All components should be installed locally. I managed to solve this with the help of several blog posts, namely:

I applied a combination of the techniques described in the previous blog posts. Essentially I did the following:

  • Installed the following files from the %ProgramFiles%\Microsoft SQL Server Compact Edition\v3.5 directory to the application’s target directory. These are the files from SQL Server CE 3.5 SP2 which came with Visual Studio 2010, though the application was created using Visual Studio 2008 SP1 (targeting .NET Framework 3.5 SP1). The version number of the files is displayed as 3.5.8080.0.
  1. sqlceca35.dll
  2. sqlcecompact35.dll
  3. sqlceer35EN.dll
  4. sqlceme35.dll
  5. sqlceoledb35.dll
  6. sqlceqp35.dll
  7. sqlcese35.dll
  • Installed the following files from the %ProgramFiles%\Microsoft SQL Server Compact Edition\v3.5\Private directory to the application’s target directory. It is important to use the files from the Private directory and not from the base and Desktop directories, otherwise other problems will arise.
  1. System.Data.SqlServerCe.dll
  2. System.Data.SqlServerCe.Entity.dll
  • Added the following section to the application’s app.config file. This was taken from the before mentioned blog post.
<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly> 
      <assemblyIdentity name="System.Data.SqlServerCe"                            publicKeyToken="89845dcd8080cc91" 
                        culture="neutral"/> 
      <bindingRedirect oldVersion="3.5.1.0-3.5.1.50" 
                       newVersion="3.5.1.50"/> 
    </dependentAssembly> 
  </assemblyBinding> 
</runtime>
  • Added the following section to the application’s app.config file. This was copied from the machine.config file of a development machine where the SQL Server CE runtime was installed. The remove tag is required to make the configuration work on machines, where this entry is already contained in the machine.config file.
<system.data>
  <DbProviderFactories>
    <remove invariant="System.Data.SqlServerCe.3.5" />
    <add name="Microsoft SQL Server Compact Data Provider"
         invariant="System.Data.SqlServerCe.3.5"
         description=".NET Framework Data Provider for Microsoft SQL Server Compact"
         type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.50, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  </DbProviderFactories>
</system.data>
  • Done.

To figure this out it was helpful to add the following entry to the registry to enable assembly binding logging. This entry causes detailed error information to be included with the exceptions thrown when assembly binding errors occur.

  • HKLM\SOFTARE\Microsoft\Fusion\EnableLog=1 (DWORD)

This solution has been tested only on Windows XP SP3 so far. Additional steps might be required to make it work on 64-bit platforms.


Aktionen

Information

One response

29 10 2011
WoAx

Very good Posting, it helped us a lot.

Its very easy and works well only to handle the dll instead of deploying the full setup.

regards

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s




%d Bloggern gefällt das: