Compact .sdf Database

G

Guest

My code falls over between line Message 1 & 2 with a SQLCEException.
OrdersDB.sdf exists, OrdersDBTmp.sdf does not.
What seems to be the problem?
Any ideas very welcome.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim srcDB As String = "OrdersDB.sdf"
Dim destDB As String = "OrdersDBTmp.sdf"

Dim engine As New SqlCeEngine("Data Source = " + srcDB)

MessageBox.Show("1")
engine.Compact(("Data Source = " + destDB))
MessageBox.Show("2")

engine.Dispose()

File.Delete(srcDB)

File.Move(destDB, srcDB)

End Sub
 
S

Sergey Bogdanov

Catch SqlCEException what error it shows? Also make sure that
OrdersDBTmp doesn't exist:

Try
If File.Exists(destDB) Then
File.Delete(destDB)
End If

... your code ...

Catch ex As SqlCeException
MsgBox("Error:" & err.NativeError)
End Try


Best regards,
Sergey Bogdanov
 
G

Guest

Thx Sergey

I had my paths wrong.

Sergey Bogdanov said:
Catch SqlCEException what error it shows? Also make sure that
OrdersDBTmp doesn't exist:

Try
If File.Exists(destDB) Then
File.Delete(destDB)
End If

... your code ...

Catch ex As SqlCeException
MsgBox("Error:" & err.NativeError)
End Try


Best regards,
Sergey Bogdanov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top