Memory problem with SqlCeEngine.Compact

  • Thread starter Mariano Vicario
  • Start date
M

Mariano Vicario

Hi all,
We are having a memory leak, in our application. The problem
is that we only can reproduce it 3 times. And we cannot find the
pattern of this bug.
In our application when the user finishes one special section, an
automatically full backup is executed (If the users setup it in this
way).

Our backup does this:

///close all DReaders, Dcomad's, and connections to de DB

SqlCeEngine engine = new SqlCeEngine("Data Source = DB.sdf"));
engine.Compact("Data Source='"DBBK.sdf ";");
engine.Dispose();

/// open connection again to the DB.sdf

The error we log is this:

Error Message:
Not enough storage is available to complete this operation.

Stack Trace:
at System.Data.SqlServerCe.SqlCeEngine.ProcessResults()
at System.Data.SqlServerCe.SqlCeEngine.Repair()
at System.Data.SqlServerCe.SqlCeEngine.Compact()
at Backup.CompactDatabaseBackUp()
at Backup.CreateBackUp()
at BackUpControl.DoBackUp()

We are using CF 2.0, and the bug was reproduce with a 3 MB DB.
As I tell you before, this happens occasionally. So I don't know what
to do, I call the GC.Collect or GC.WaitForPendingFinalizers always
before SqlCeEngine.Compact is call?, or do I have any way to know how
memory is at the moment, and if is necessary I call GC.Collect ?

Thanks,
Mariano Vicario
www.ranu.com.ar
 
C

Christian Resma Helle

From the exception message my first guess was that a free space problem
(also coz I had this problem before, and it was a free space problem that I
didn't notice immediately). Have you tried watching the Memory control panel
applet (Settings - System - Memory) while your application is running?

If it is a memory problem then you would get an OutOfMemoryException. If the
device is running low on memory, your application would receive a
WM_Hibernate message from the OS (you can handle this through the
Microsoft.WindowsCE.Forms.MobileDevice.Hibernate event) and you're supposed
to try to clean up a little (like closing database connections, clearing
caches, etc..)
 

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