Article ID: 279552 - Last Review: February 22, 2007 - Revision: 1.8

How To Delete a SQL Server CE Database in an Application

This article was previously published under Q279552
Expand all | Collapse all

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.

APPLIES TO
  • Microsoft SQL Server 2000 Windows CE Edition 2.0
  • Microsoft SQL Server 2000 Windows CE Edition 1.1 Service Pack 1
  • Microsoft SQL Server 2000 Windows CE Edition 1.1
  • Microsoft SQL Server 2000 Windows CE Edition
Keywords: 
kbhowto KB279552
 

Article Translations

 

Related Support Centers