Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SQLCE V3.5 - SqlCECommand.ExecuteScalar Memory Leak?

128 views
Skip to first unread message

Greg Hellem

unread,
Sep 8, 2011, 12:07:31 AM9/8/11
to
Ladies and Gentlemen,
I submit the following code-snippet for a simple method whose only purpose
is to check on the number of records (rows) in a SqlCE (V3.5) Table:
public int DoSqlScaler(string command)
{
int retVal = 0;
SqlCeCommand cmnd = new SqlCeCommand(command, localConnection);
try
{
retVal = (int)cmnd.ExecuteScalar();
}
catch (SqlCeException sqlex)
{
exceptionMsg = "SQLCE Error: " + sqlex.Message;
}
return retVal;
}

Caller:
if (DoSqlScalar("SELECT COUNT(*) FROM TABLE_NAME") > 0)
...process rows...

The "Caller" executes the above "if statement" once every second, and
processes any records (rows) with a seperate method that uses
cmd.ExecuteResultSet()... However, my following results occur without ANY
rows in the table! So what's the problem, you ask? The above method consumes
an incredible 10MB+ within 10-15 minutes!! And can ultimately consume up to
15MB...Why? During execution there are NEVER any records in the target
Table!!

The localConnection is opened once, at the begining of the program, and is
never closed until the program ends. The connection string is defined as:
string appDir =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
string fileName = appDir + "\\CommQueue.sdf";
localConnection = string.Format("Persist Security Info = False;
DataSource=\"{0}\"; Password='{1}'; File Mode = 'read write'; Max Buffer
Size = 2048", fileName, "OU812");

This program is the only app accessing the local database, and is using a
single thread to do so. Also, the catch statement never gets hit. Again...
There are NEVER any records (rows) in the SqlCE Database Table. I've seen
several posts regarding SQLCE/ExecuteScalar and memory leaks but they all
seem to think that the problem is due to incorrect disposal/closure of the
database connection (localConnection above). However, again, my code opens
the connection and uses it for the duration of program execution, and is
properly disposed of (closed, set to null, etc.) when the application exits.

Any ideas?
Thank you for your time,
- Greg


0 new messages