Create SQL Server CE database file programmatically

Andrew Arnott picture Andrew Arnott · Sep 28, 2009 · Viewed 36.1k times · Source

How can I create a new SQL Server Compact database file (.sdf) programmatically, without having an existing template file to copy from?

Answer

D'Arcy Rittich picture D'Arcy Rittich · Sep 28, 2009

There is some good info here: Create a SQL Server Compact Edition Database with C#

string connectionString = "DataSource=\"test.sdf\"; Password=\"mypassword\"";
SqlCeEngine en = new SqlCeEngine(connectionString);
en.CreateDatabase();