Microsoft KB Archive/279552

= How To Delete a SQL Server CE Database in an Application =

Article ID: 279552

Article Last Modified on 2/22/2007

-

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 Encarta Interactive World Atlas 2001
 * 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 = &quot;ADOXDB.sdf&quot; Private Sub Command1_Click Dim Createdb As Variant Set Createdb = CreateObject(&quot;adoxce.catalog.3.1&quot;) Dim Connection As String Connection = &quot;Provider=Microsoft.SQLServer.OLEDB.CE.1.0;Data Source=&quot; & DestinationDBName

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

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

