Help! How to properly flush the database with ADOCE?

G

Guest

After noticing that I was losing data after a soft reset, the kind people of this newsgroup informed me that I need to flush the database to permanantly commit any data. Has anybody come up with a proven way to do this without causing the application to crash? I am currently using the following VB.NET code which actually does the trick except that it causes the application to crash frequently

'*****************************
Imports System.Runtime.InteropService
Public Class FlushD

<DllImport("coredll.dll")>
Private Shared Function CeMountDBVol(ByVal pGUID As Byte(), ByVal lpszVol As String, ByVal dwFlags As Integer) As Intege
End Functio

<DllImport("coredll.dll")>
Private Shared Function CeFlushDBVol(ByVal pGUID As Byte()) As Intege
End Functio

<DllImport("coredll.dll")>
Private Shared Function CeUnmountDBVol(ByVal pGUID As Byte()) As Intege
End Functio

Public Shared Sub Commit(ByVal DBPath As String
Dim guid() As Byte = New Byte(8) {
CeMountDBVol(guid, DBPath, 3
CeFlushDBVol(guid
CeUnmountDBVol(guid
End Su

End Clas
'*********************************************

I call this routine everytime I enter a record on a form. It does what I want it to do in that it saves the most recent record if I soft reset the device. However, like a lot of people have experienced, the application becomes very unstable and will crash after entering 10 or so records. This obviously has to have been an issue with a ton of applications out there so there has to be someone who has figured this out! If anybody could post some code (VB.NET) and or any other suggestions so that I can avoid data loss on a soft reset it would be greatly appreciated

Thanks

Mike
 
J

Jan Yeh [MVP]

Hello, Mike

My work around is to close connection and re-open it.
Sounds ugly, but it works and takes a little more time to go.

I believe that there are better ways to flush data into DB,
but this is an available solution. You can wait for better ones.

--
Best Regards,
Jan Yeh

eMVP, MCAD, .NETcf Developer
Mobile Mind Company @ Taiwan

Mike said:
After noticing that I was losing data after a soft reset, the kind people
of this newsgroup informed me that I need to flush the database to
permanantly commit any data. Has anybody come up with a proven way to do
this without causing the application to crash? I am currently using the
following VB.NET code which actually does the trick except that it causes
the application to crash frequently.
'******************************
Imports System.Runtime.InteropServices
Public Class FlushDb

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

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

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

Public Shared Sub Commit(ByVal DBPath As String)
Dim guid() As Byte = New Byte(8) {}
CeMountDBVol(guid, DBPath, 3)
CeFlushDBVol(guid)
CeUnmountDBVol(guid)
End Sub

End Class
'**********************************************

I call this routine everytime I enter a record on a form. It does what I
want it to do in that it saves the most recent record if I soft reset the
device. However, like a lot of people have experienced, the application
becomes very unstable and will crash after entering 10 or so records. This
obviously has to have been an issue with a ton of applications out there so
there has to be someone who has figured this out! If anybody could post
some code (VB.NET) and or any other suggestions so that I can avoid data
loss on a soft reset it would be greatly appreciated!
 
G

Guest

Jan Yeh

Thanks for your reply. I have tried this approach but it doesnt seem to do the trick? Every time the user pushes the 'Enter' button on the form I would write the current record to my Data Table, close the connection, dispose of the connection and set the connection = nothing and then reopen the connection. But, after entering a few records and soft reseting, my data still was not saved? At this point I'm not even concerned about performance I just need to make sure my users arent losing any data! Were you doing this at any particular point in your application? Any ideas why this wouldnt work for me

Thanks

Mike
 
P

Peter Foot [MVP]

The only way to hard flush the database is using the CeDb P/Invokes
described in your previous post. However you should not call these while
your Recordset and Connection objects are open - this totally confuses
ADOCE and this will generally crash the entire application. Generally you
would reserve such a flush to events such as shutting down the application
or over a greater time period (if the app is running more or less
continuously). Calling this between every individual write will kill
performance, especially as you need to close and recreate connections
in-between flushes.
This is a limitation of both the underlying CeDb engine (which caches all
writes until you flush the volumne) and ADOCE which appears to add its own
caching on top of this. It is made worse by the fact that calling CeDb
functions on a volume that is in use by ADOCE is unstable and yet ADOCE
doesn't expose any way to commit changes itself.

Peter
 
G

Guest

Thanks Peter,

I think this information will be helpful to a lot of people. So I guess the message to take home is that there is no true way to ensure that not a single record will be lost

In your opinion, what would be a reasonable interval to flush the database via the P/Invoke and the opening and closing the connections? In other words what might be a good balance between performance and preserving your data? Do you think every 10-15 minutes would be to much? Or another option would be every 20 records or something (which would also take between 10 -15 minutes)

Thanks

Mike
 
J

Jan Yeh [MVP]

After your user make some important changes, it would be a good time
to save. You may also provide a "Save" button in your application,
so users knows they have to press it to keep their data.

Considering performance and preserving data, it depends on the situation.

--
Best Regards,
Jan Yeh

eMVP, MCAD, .NETcf Developer
Mobile Mind Company @ Taiwan

Mike said:
Thanks Peter,

I think this information will be helpful to a lot of people. So I guess
the message to take home is that there is no true way to ensure that not a
single record will be lost.
In your opinion, what would be a reasonable interval to flush the database
via the P/Invoke and the opening and closing the connections? In other
words what might be a good balance between performance and preserving your
data? Do you think every 10-15 minutes would be to much? Or another option
would be every 20 records or something (which would also take between 10 -15
minutes).
 

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