How To Delete a SQL Server CE Database in an Application (279552)



The information in this article applies to:

  • Microsoft SQL Server 2000 Windows CE Edition 2.0
  • Microsoft SQL Server 2000 Windows CE Edition 1.1 SP1
  • Microsoft SQL Server 2000 Windows CE Edition 1.1
  • Microsoft SQL Server 2000 Windows CE Edition

This article was previously published under Q279552

SUMMARY

SQL Server 2000 for Windows CE (SSCE) supports a CREATE DATABASE command as well as Microsoft ActiveX Data Objects Extensions for Data Definition Language and Security (ADOX), OLE DB and AddSubscription methods to create a database. However, SQL Server 2000 for Windows CE does not support a DROP DATABASE command. You can use a file system object to delete a database programmatically.

MORE INFORMATION

Use the following code to create and drop a database programmatically. Paste the code into a Microsoft eMbedded Visual Basic (eVB) application, add two command buttons, and then add the file system reference in addition to SQL CE, Microsoft ADO for Windows CE SDK (ADOCE) 3.1 and Microsoft CE ActiveX Data Objects (ADOXCE) 3.1 references.

Note If you are using SQL Server CE 2.0, modify the connect string to change the provider: Microsoft.SQLServer.OLEDB.CE.2.0.

Const DestinationDBName = "ADOXDB.sdf"
Private Sub Command1_Click()
    Dim Createdb As Variant
    Set Createdb = CreateObject("adoxce.catalog.3.1")
    Dim Connection As String
    
    Connection = "Provider=Microsoft.SQLServer.OLEDB.CE.1.0;Data Source=" & DestinationDBName

    Createdb.Create Connection
    If Err.Number <> 0 Then
        MsgBox "Create " & DestinationDBName & " failed"
    Else
        MsgBox "Create " & DestinationDBName & " success"
End If
End Sub

Private Sub Command2_Click()
    Dim FileSystem As Variant
    Set FileSystem = CreateObject("FILECTL.FileSystem")
    FileSystem.Kill DestinationDBName
    If Err.Number <> 0 Then
        MsgBox "DB " & DestinationDBName & " Delete failure"
    Else
        MsgBox "DB " & DestinationDBName & " Delete success"
    End If
End Sub
				
With SQL Server CE 2.0, SQL Query Analyzer includes a button to drop (delete) a database.

REFERENCES

For additional information, see the "Managing Database Objects in the Objects Tab" and "Creating a Database" topics in SQL Server CE Books Online.

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbhowto KB279552