How to Flush the database!

G

Guest

I am trying to ensure minimal data loss in the event of a soft reset for my
data collection application. I am trying to use CeMountDBVol, CeFlushtDBVol,
CeUnMountDBVol, to do this but cant get it to work properly.

I would be extremely grateful to anyone who could post a quick code snippet
in VB.NET that they know works! Additionally, I would be interested to know
how and where to use it. For example, can I flush the database after every
record entry without adverse affects? Any other relevant information
relevant to this process would be welcome as well.

Thanks!

Mike
 
P

Peter Foot [MVP]

This should do it in VB:-

Public Shared Sub Flush(ByVal DBPath As String)
Dim guid As Guid = Guid.Empty
CeMountDBVol(guid, DBPath, 3)
CeFlushDBVol(guid)
CeUnmountDBVol(guid)
End Sub

<DllImport("coredll.dll")> _
Private Function CeMountDBVol(ByRef pGUID As Guid, ByVal lpszVol As String,
ByVal dwFlags As Integer) As Integer
End Function

<DllImport("coredll.dll")> _
Private Function CeFlushDBVol(ByRef pGUID As Guid) As Integer
End Function

<DllImport("coredll.dll")> _
Private Function CeUnmountDBVol(ByRef pGUID As Guid) As Integer
End Function

Peter
 
G

Guest

Chris-

I am putting the data into a .cdb database (FYI, via InTheHand ADOCE) and I
am doing this with a combination of bound controls on a form and "hard
coding" some values. So, for example..

'via Hard coding
dtSampleInfo_Indexing.Rows(Me.BindingContext(dtSampleInfo_Indexing).Count -
1)("SampleID") = g_SampleID

'via Bound fields
txtLocation.DataBindings.Add(New Binding("Text", dtSampleInfo_Indexing,
"Location"))

Is that what you mean?

Thanks,

Mike
 
G

Guest

Thanks Peter-

First, This is probably a dumb question but, when I just copy and paste your
code I get the following errors in my Task List

"Cannot refer to an instance member of a class from within a shared method
or shared member initializer without an explicit instance of the class."

for each of the CEMount, CEFlush, CEUnmount references in Sub Flush. If I
remove the 'Shared' I no longer get that error. Is that going to cause a
problem?

Secondly, is there any reason I couldnt call Flush(DBPath), assuming I have
closed all connections and dataadapters, after every data entry thus never
really lose any data if a Soft Reset were to happen?

Thanks!
 
G

Guest

If I do need it to be static (shared), any idea why I am getting the error

"Cannot refer to an instance member of a class from within a shared method
or shared member initializer without an explicit instance of the class."

when I use Public Shared....What I need to do to fix it?

As the code stands (unshared), my application will crash when I call the
Flush(db) sub.

Mike
 
P

Peter Foot [MVP]

Apologies, the code was copy/pasted out of a VB module where all methods are
shared by default, and I didn't update them all, use this instead:-

Public Shared Sub Flush(ByVal DBPath As String)
Dim guid As Guid = Guid.Empty
CeMountDBVol(guid, DBPath, 3)
CeFlushDBVol(guid)
CeUnmountDBVol(guid)
End Sub

<DllImport("coredll.dll")> _
Private Shared Function CeMountDBVol(ByRef pGUID As Guid, ByVal lpszVol As
String,
ByVal dwFlags As Integer) As Integer
End Function

<DllImport("coredll.dll")> _
Private Shared Function CeFlushDBVol(ByRef pGUID As Guid) As Integer
End Function

<DllImport("coredll.dll")> _
Private Shared Function CeUnmountDBVol(ByRef pGUID As Guid) As Integer
End Function

Peter
 
P

Peter Foot [MVP]

There is a quite a performance penalty if you call this too regularly, but
it's really going to depend on how often you expect every data entry to be
made. You'll probably need to try it after every record is added and see
what effect it has on application responsiveness.

Peter
 

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