Non-installed usage of SQL Server CE 4.0 in a WPF application

1

I have a wpf application that accesses data within a SQL Server CE database. The application and database are meant to be run on a PC without installation, however attempting to do so fails. (failure to locate db provider) I've taken the following steps:

  • System.Data.SqlServerCE -> copy local
  • copied 7 SQL Server CE assemblies into application directory
  • verified that VC++ is available on system
  • added following to app.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>
    

On attempted execution of the following code:

  try
  {
    MessageBox.Show("initialize db connection");
    context = new DataAccess.PersistentStorageEntities();
    MessageBox.Show(context.Database.Connection.ConnectionString);
  }
  catch (Exception ex)
  {
    MessageBox.Show("exception: "+ex.Message);
    if (ex.InnerException != null)
    {
      MessageBox.Show("innerexception: "+ ex.InnerException.Message);  
    }
  }

I get the message:

exception: is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

I suspect it's having trouble loading the System.Data.SqlServerCe.4.0 , but can't figure out why it would be trying to load as Win32

Any thoughts? I feel like I'm losing my mind here

wpf
entity-framework
sql-server-ce
asked on Stack Overflow Feb 6, 2013 by lostinplace • edited Feb 6, 2013 by marc_s

1 Answer

1

1: You must use the System.Data.SqlServerCe dll from the Private folder (and the System.Data.SqlServerCe.Entity.dll dll from the same folder).

2: You must add x86 and AMD64 folders to your project, and include the required files (including the private VC++ runtime folder) in each (like in the Private folder). Make sure to include all files as content

3: You must change the config reference to version 4.0.0.1

See my blog for more detailed info: "Using SQL Server Compact 4.0 with Desktop Private Deployment and a Setup project (MSI) (part 2)"

answered on Stack Overflow Feb 7, 2013 by ErikEJ

User contributions licensed under CC BY-SA 3.0