Compattare Database CE






http://support.microsoft.com/kb/306452/it


Private Sub Command1_Click()

'compatta database CE



On Error Resume Next
Dim DBEngine As Object
Dim oFS As Object
Dim srcConn As String
Dim destConn As String
Dim txtlog as String

Err = False
srcConn = "Provider=Microsoft.SQLServer.OLEDB.CE.1.0;Data Source=\sourceDB.sdf"
destConn = "Provider=Microsoft.SQLServer.OLEDB.CE.1.0;Data Source=\destinDB.sdf"
Set oFS = CreateObject("Filectl.FileSystem")

' Make sure there isn't already a file with the name of the compacted database.

If oFS.Dir("destinDB.sdf") <> "" Then
oFS.Kill "destinDB.sdf"
txtlog.Text = "drop destinDB.sdf complete" & vbCrLf
End If

Set DBEngine = CreateObject("SSCE.Engine.1.0")

' This statement creates a compact version of the database

DBEngine.CompactDatabase srcConn, destConn
If Err Then
txtlog = txtlog & "Error: " & Err.Number & " " & Err.Description
Else
txtlog = txtlog & "compactDB complete" & vbCrLf
oFS.Kill "\sourceDB.sdf"
txtlog = txtlog & "drop \sourceDB.sdf complete" & vbCrLf
oFS.MoveFile "destinDB.sdf", "sourceDB.sdf"
End If

msgbox txtlog

Set DBEngine = Nothing
Set oFS = Nothing
End Sub










( compattaredatabasece.html )- by Paolo Puglisi - Modifica del 17/12/2023