Jaa


How to: Delete a Database (Programmatically)

In this topic, you will learn how to delete a Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) database. Because SQL Server Compact Edition databases are files in the file system, you delete a SQL Server Compact Edition database by deleting the file.

To delete a SQL Server Compact Edition database

  • Call the System.IO.File.Delete method and pass in the path and file name of the SQL Server Compact Edition database.

    File.Delete("Test.sdf");
    

Example

This example deletes an existing SQL Server Compact Edition database, and then creates a new one.

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

Working with Databases (SQL Server Compact Edition)

Help and Information

Getting SQL Server Compact Edition Assistance