Create SQLCE database programmatically [duplicate]
This question already has an answer here: Create SQL Server CE database file programmatically 2 answers [EDITED - with answer] Following is my code to create SQL CE database programmatically: /* get the Path */ var directoryName = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var fileName = System.IO.Path.Combine(directoryName, "Foo2Database.sdf"); /* check if exists */ if (File.Exists(fileName)) File.Delete(fileName); string connStr = @"Data Source = " + fileName; /* create Database */ SqlCeEngine engine = new SqlCeEngine(connStr); engine.CreateDatabase(); /* create