lostinplace
lostinplace

Reputation: 1518

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

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:

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

Upvotes: 1

Views: 692

Answers (1)

ErikEJ
ErikEJ

Reputation: 41819

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)"

Upvotes: 1

Related Questions