How to: Delete a Database (Programmatically)

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

Procedures for SQL Server Compact 4.0

To delete a database

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

    File.Delete("Test.sdf");
    

Example

This example deletes the existing SQL Server Compact database named Test.sdf.

using System.IO;

namespace MySQLCEApplication
{
    class Program
    {
        static void Main(string[] args)
        {
         // Call the File class Delete method to delete the database.
            File.Delete("Test.sdf");
        }
    }
}
Imports System.IO

Module Module1

    Sub Main()
        'Call the File class Delete method to delete the database.
        File.Delete("Test.sdf")

    End Sub

End Module

See Also

Other Resources

Working with Databases (SQL Server Compact)