SQL Server Mobile 3.0 - Out of Memory Exception

M

Michael Wenninger

Hello NG,

I develop an application with CF 2.0 SP1 and SQL Server Mobile 3.0. My
application is ready and works fine, however after a few minutes I get a
OOM - message. I could already limit the problem to the SQL Server. I have a
timer in my application, that execute every 5 seconds a simply
SQL-Statement:

[...]
private void timer_Tick(object sender, EventArgs e)
{
SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs",
_con);
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}

[...]

After a few minutes no more memory is available. I have written a simply
test-application with the same code snippet in CF1.0 / SQL CE 2.0 and there
is no problem.
Is there a memoryleak in the SQL Server Mobile 3.0 ?

Thanks
Michael
 
F

Functional Illiterate

Yup,

Better yet, put it and all other SQL commands in using blocks.

private void timer_Tick(object sender, EventArgs e)
{
using (SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs", _con) )
{
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}
}

-F

Try calling cmd.Dispose at the end of the method and see if it changes
things.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Michael Wenninger said:
Hello NG,

I develop an application with CF 2.0 SP1 and SQL Server Mobile 3.0. My
application is ready and works fine, however after a few minutes I get a
OOM - message. I could already limit the problem to the SQL Server. I have
a
timer in my application, that execute every 5 seconds a simply
SQL-Statement:

[...]
private void timer_Tick(object sender, EventArgs e)
{
SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs",
_con);
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}

[...]

After a few minutes no more memory is available. I have written a simply
test-application with the same code snippet in CF1.0 / SQL CE 2.0 and
there
is no problem.
Is there a memoryleak in the SQL Server Mobile 3.0 ?

Thanks
Michael
 
M

Michael Wenninger

Where is the difference ?

using(SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs",
_con))
{
[...]
}


SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs", _con)
[...]
cmd.Dipose();

The using - statement calls iternally the Dispose-method i think.

Michael


Functional Illiterate said:
Yup,

Better yet, put it and all other SQL commands in using blocks.

private void timer_Tick(object sender, EventArgs e)
{
using (SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs", _con) )
{
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}
}

-F

Try calling cmd.Dispose at the end of the method and see if it changes
things.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Hello NG,

I develop an application with CF 2.0 SP1 and SQL Server Mobile 3.0. My
application is ready and works fine, however after a few minutes I get a
OOM - message. I could already limit the problem to the SQL Server. I have
a
timer in my application, that execute every 5 seconds a simply
SQL-Statement:

[...]
private void timer_Tick(object sender, EventArgs e)
{
SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs",
_con);
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}

[...]

After a few minutes no more memory is available. I have written a simply
test-application with the same code snippet in CF1.0 / SQL CE 2.0 and
there
is no problem.
Is there a memoryleak in the SQL Server Mobile 3.0 ?

Thanks
Michael
 
F

Functional Illiterate

IMO, the main difference comes in when you start looking at exception
handling and ease of coding. If your code happens to throw some
exception in connecting to the DB or in the code between creating the
cmd and hitting the Dispose(), the using pattern makes sure the command
object is disposed. Like the documentation says, using functions as a
try-finally. Its just a lot less typing, brackets, indentation, etc.

fi

Michael said:
Where is the difference ?

using(SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs",
_con))
{
[...]
}


SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs", _con)
[...]
cmd.Dipose();

The using - statement calls iternally the Dispose-method i think.

Michael


Functional Illiterate said:
Yup,

Better yet, put it and all other SQL commands in using blocks.

private void timer_Tick(object sender, EventArgs e)
{
using (SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs", _con) )
{
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}
}

-F

Try calling cmd.Dispose at the end of the method and see if it changes
things.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Hello NG,

I develop an application with CF 2.0 SP1 and SQL Server Mobile 3.0. My
application is ready and works fine, however after a few minutes I get a
OOM - message. I could already limit the problem to the SQL Server. I have
a
timer in my application, that execute every 5 seconds a simply
SQL-Statement:

[...]
private void timer_Tick(object sender, EventArgs e)
{
SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs",
_con);
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}

[...]

After a few minutes no more memory is available. I have written a simply
test-application with the same code snippet in CF1.0 / SQL CE 2.0 and
there
is no problem.
Is there a memoryleak in the SQL Server Mobile 3.0 ?

Thanks
Michael
 
B

Boomhauer

cache this command object outside the scope of the method instead of
creating it each time. This will also help with performance as well as
mem mgt.

in my cf.net 1.0 apps, i would typically keep command objects defined
for the life of the app (when applicable) mostly for performance
reasons. never ran into probs doing this.

Brady

Functional said:
IMO, the main difference comes in when you start looking at exception
handling and ease of coding. If your code happens to throw some
exception in connecting to the DB or in the code between creating the
cmd and hitting the Dispose(), the using pattern makes sure the command
object is disposed. Like the documentation says, using functions as a
try-finally. Its just a lot less typing, brackets, indentation, etc.

fi

Michael said:
Where is the difference ?

using(SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs",
_con))
{
[...]
}


SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From Jobs", _con)
[...]
cmd.Dipose();

The using - statement calls iternally the Dispose-method i think.

Michael


Functional Illiterate said:
Yup,

Better yet, put it and all other SQL commands in using blocks.

private void timer_Tick(object sender, EventArgs e)
{
using (SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs", _con) )
{
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}
}

-F

<ctacke/> wrote:
Try calling cmd.Dispose at the end of the method and see if it changes
things.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Hello NG,

I develop an application with CF 2.0 SP1 and SQL Server Mobile 3.0. My
application is ready and works fine, however after a few minutes I get a
OOM - message. I could already limit the problem to the SQL Server. I have
a
timer in my application, that execute every 5 seconds a simply
SQL-Statement:

[...]
private void timer_Tick(object sender, EventArgs e)
{
SqlCeCommand cmd = new SqlCeCommand("Select Count(*) From
Jobs",
_con);
object objCount = cmd.ExecuteScalar();
int countRow = (int)objCount;
this.lblJobCount.Text = countRow.ToString();
}

[...]

After a few minutes no more memory is available. I have written a simply
test-application with the same code snippet in CF1.0 / SQL CE 2.0 and
there
is no problem.
Is there a memoryleak in the SQL Server Mobile 3.0 ?

Thanks
Michael
 

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