How to: Create a SQL Server Compact Edition Database by Using the Engine Object (Programmatically)
In this topic, you will learn how to programmatically create a Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) database by using the CreateDatabase method of the SqlServerCe.Engine object. For more information about using the SqlServerCe namespace, see the SqlServerCe namespace reference documentation.
To create a SQL Server Compact Edition database by using the Engine object
Initialize a new Engine object.
SqlCeEngine engine = new SqlCeEngine();
Set the LocalConnectionString property of the Engine object. The LocalConnectionString property specifies the name and location of the database that will be created, and might specify additional database options, including encryption.
eng.LocalConnectionString= "Data Source='Test.sdf'; LCID=1033;" + "Password='s$;2'!dS64'; Encrypt = TRUE;";
Call the CreateDatabase method to create the database.
engine.CreateDatabase();
Example
This example creates a new database named Test.sdf.
System.IO.File.Delete("Test.sdf");
string connString = "Data Source='Test.sdf'; LCID=1033; Password=\"s$;2'!dS64\"; Encrypt = TRUE;";
SqlCeEngine engine = new SqlCeEngine(connString);
engine.CreateDatabase();
System.IO.File.Delete("Test.sdf")
Dim connString As String = "Data Source='Test.sdf'; LCID=1033; Password=""s$;2'!dS64""; Encrypt = TRUE;"
Dim engine As New SqlCeEngine(connString)
engine.CreateDatabase()
See Also
Other Resources
Overview of Database Engine (SQL Server Compact Edition)