Friday, October 24, 2008 6:51 PM
I have a simple test where I'm trying to save company information back to my .sdf file in the Closing event of my mobile form.
While debugging, I checked the dataset and it has the changes and the Update() returns 1
The .sdf exists in my website under, the c:\inetpub\wwwroot\<project> folder but in the debugger, it says the connection string is "Data Source =\\Program Files\\SmartDeviceCompanyEditor\\Companies.sdf;"
I also see a copy of the sdf gets copied to the debug output folder and that I should have the Companies.sdf in my project set to "Copy if newer".
However, I tried this and I still can't get the changes to stick. When I view the data in the .sdf, nothing has changed.
Monday, October 27, 2008 5:25 AM
There is a problem with the way you are expecting the changes to be written on the disk.
You are calling the adapter.update on form closing.
This succesfully returns as you mentioned, however, it does not imply that the changes are written out to the database file.
Whenever you commit some changes to SQLCe, these are kept in the memory for performance reasons.
Writing out to the disk file for every change will be a very costly operation.
The changes are written out to the disk after a time called the flush interval. The default value is 10 sec(so you undersand why the changes will never be written to the disk) but it can be changed when you open the connection to the file.
Having understood the problem and the cause.
You can choose from a number of fixes:
1. Specify a very small value to the flush interval so that the changes are quickly written to the db file.
This would work efficiently when you are not writing too much to the db file. Because otherwise, your application performance might go down if you write the contents back to the disk for every write.
2. Change the logic for calling adapter.update. Instead of saving changes when form is closed, add a button "save changes" to the form and call adapter.update when the user clicks on it.
I would recommend this approach.
It is not wise to call adapter.update in form.close event. Because there is little corrective action that you can take if adapter.update fails. All user changes will be lost since the form is closed. At best he will end up with a msgbox saying there was a failure.
Wednesday, March 07, 2012 3:47 AM
I am having a very similar issue, and the code isn't very complicated. The new dat is shown in the dataset, but it doesn't make it back to the database. I'm not sure what I am missing.
'Add a Record Me.MachinesTableAdapter.InsertMachineName(tbxMachineName.Text) 'End Editing Me.MachinesBindingSource.EndEdit() 'Update Table Adapter Me.MachinesTableAdapter.Update(Me.FlowMetersDataSet.Machines) 'Refill with the data Me.MachinesTableAdapter.Fill(Me.FlowMetersDataSet.Machines)
I think I may be missing a key concept here. I want to save this data to the SDF file, isn't that done through the Table adapter?
Friday, March 23, 2012 7:17 AM