SQL Server Compact 3.5 SP2 Private Deployment


  • I have an application that uses SSC in private deployment mode. I recently upgraded the applicaton to use .NET 4.0 Entity Framework from LINQ to SQL. After the upgrade I added a reference to the System.Data.SqlServerCe.Entity.dll from the C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Private folder. But I get the following error:

    [A]System.Data.SqlServerCe.SqlCeConnection cannot be cast to [B]System.Data.SqlServerCe.SqlCeConnection. Type A originates from 'System.Data.SqlServerCe, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\Users\Gaurav Shah\Documents\visual studio 2010\Projects\eDoc Organizer 2010\Launcher\bin\x86\Debug\System.Data.SqlServerCe.dll'. Type B originates from 'System.Data.SqlServerCe, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\\System.Data.SqlServerCe.dll'.

    Upon further investigation it seems like the problem is that the System.Data.SqlServerCe.dll' in the private folder is version, but EF is loading from the GAC. I found this other post ( where ErikEJ mentions that System.Data.SqlServerCe.Entity.dll in the private folder is referencing the wrong version of System.Data.SqlServerCe, instead of How do I correct this problem? I would like to do private deployment and if the assembly System.Data.SqlServerCe.Entity.dll is compiled with the wrong version of SqlServerCe dll, is private deployment not possible with SSC 3.5 SP2?

    Thank you,

    Sunday, April 25, 2010 12:18 PM

All replies

  • Have you installed 3.5 SP2 RTM (version 3.5.8080.0) ?

    This is from the SQL Server Compact 3.5 SP2 Books online:

    To develop a desktop application that uses private deployment of SQL Server Compact 3.5:

    1. Ensure that updates are current for SQL Server Compact 3.5 on the development computer.
    2. Add any references to the two SQL Server Compact managed assemblies to your project by browsing to the %Program Files%\Microsoft SQL Server Compact Edition\v3.5\Private folder in the Add Reference dialog box in Visual Studio. (For applications that use central deployment, these references are added from the . NET tab.)
    3. Add any required native libraries to the project. These should be added by browsing to the %Program Files%\Microsoft SQL Server Compact Edition\v3.5 folder, the %Program Files(x86)%\Microsoft SQL Server Compact Edition\v3.5 folder, or both. The folder from which you add the native libraries depends on the platform ( x86 , x64 , or Any CPU ) for which you are developing your application. At a minimum, the following native assemblies must be added: sqlceme35.dll, ssceqp35.dll, sscese35.dll, and sqlceer35xx.dll.
    4. Ensure that the managed assemblies and the native libraries added above are copied to the build output.

    Please let me know if this works for you. Erik Ejlskov Jensen - Please mark as answer, if this was it.
    Sunday, April 25, 2010 2:43 PM
  • Hello Erik,

    I think 3.5 SP2 RTM was installed when I installed VS 2010 Ultimate. I checked that the dlls in the private folder are version 3.5.8080.0. I have been doing some more investigation and here is what I found out. I have the following section in the app.config file:

       <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=, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    I thought I read a long time ago on your blog that I had to do that for private deployment. If I remove this section than the method described in your post works. If I include it, it causes the error that I posted in my initial question. Is this section no longer required in the app.config file for private deployment?
    Sunday, April 25, 2010 3:54 PM
  • OK, the rules have changed (to the better == more easy solution).

    So the guidelines in the SP2 docs work, and no modifications of app.config are any longer required, is that the conclusion? Erik Ejlskov Jensen - Please mark as answer, if this was it.
    Sunday, April 25, 2010 4:10 PM
  • I am not sure yet, more testing will be required on a machine where SSCE is not installed. See on my machine it might be working since I have the SSCE dlls in GAC. I will test the solution on a machine without compact edition installed and let you know.


    Sunday, April 25, 2010 4:20 PM
  • Great - you could also simply uninstall from your dev PC. Erik Ejlskov Jensen - Please mark as answer, if this was it.
    Sunday, April 25, 2010 4:22 PM
  • Unfortunately, it seems like the app.config section is still needed, especially on machines that don't have SSCE installed on them. But even with the section I can't get any combination of the System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll to work in a private deployment scenario. As per your finding Erik the problem seems to be that System.Data.SqlServerCe.Entity.dll wants to load a different version of the dll and that dll version is not available for private deployment. I guess the only fix would be if Microsoft recompiled the entities dll with the correct version and provided a patch.


    Sunday, April 25, 2010 6:20 PM
  • Hi Karlie,

    Please refer this blog article for details about the issue and resolution:




    Monday, May 17, 2010 3:26 PM