Create SQL Server CE Database Program File

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

+48
c # database sql-server sql-server-ce
Sep 28 '09 at 15:56
source share
2 answers

There is some useful information here: Create a SQL Server Compact Edition database using C #

string connectionString = "DataSource=\"test.sdf\"; Password=\"mypassword\""; SqlCeEngine en = new SqlCeEngine(connectionString); en.CreateDatabase(); 
+71
Sep 28 '09 at 16:01
source share

First go to the Overview tab. Now go to C:\Program Files\Microsoft SQL Server Compact Edition\v3.1 . Now select System.Dadta.SqlServerCe.dll , click on it, then click OK to get the link.

Now let's write some code. First, go to the head of the class, I call the title of your class and create a link to use.

 using System.Data.SqlServerCe; using System.IO; string connectionString; string fileName = "aminescm.sdf"; string password = "aminescm"; if (File.Exists(fileName)) { File.Delete(fileName); } connectionString = string.Format( "DataSource=\"{0}\"; Password='{1}'", fileName, password); SqlCeEngine en = new SqlCeEngine(connectionString); en.CreateDatabase(); 

You can find more and more about it, this is a really amazing website:

http://arcanecode.com/arcane-lessons/

+7
Jun 06 2018-12-12T00:
source share



All Articles