If you have installed SQL Server Compact 4.0 on the target machine, your app must work without additional installations.
If you want to distribute your app with embedded SQL Server Compact, do the following:
1. Add "C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private" content to you app including the amd64 and x86 subfolders. Set the Build Action as
Content and Copy to Output Directory as
Copy if newer for all the items. This is the "Private" deployment.
2. Add the following code in the app.config:
<configuration>
<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.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</add></dbproviderfactories>
</system.data>
</configuration>
This code targets to the 4.0.0.1 version.
That's all. Your app will work with SQL Server Compact databases on any x64/x86 machine.