Re: SQL Server Mobile 3.0 - Out of Memory Exception
- From: "Functional Illiterate" <functionalilliterati@xxxxxxxxx>
- Date: 18 Sep 2006 07:59:40 -0700
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 Wenninger wrote:
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" <functionalilliterati@xxxxxxxxx> schrieb im
Newsbeitrag news:1158332658.788458.28280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Yup,message
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
--
"Michael Wenninger" <mwenninger@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
anews:eyWpcFK2GHA.480@xxxxxxxxxxxxxxxxxxxxxxx
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
haveOOM - message. I could already limit the problem to the SQL Server. I
simplya
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
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
.
- Follow-Ups:
- Re: SQL Server Mobile 3.0 - Out of Memory Exception
- From: Boomhauer
- Re: SQL Server Mobile 3.0 - Out of Memory Exception
- References:
- SQL Server Mobile 3.0 - Out of Memory Exception
- From: Michael Wenninger
- Re: SQL Server Mobile 3.0 - Out of Memory Exception
- From: <ctacke/>
- Re: SQL Server Mobile 3.0 - Out of Memory Exception
- From: Functional Illiterate
- Re: SQL Server Mobile 3.0 - Out of Memory Exception
- From: Michael Wenninger
- SQL Server Mobile 3.0 - Out of Memory Exception
- Prev by Date: Re: Error in MSMQ MessageQueue.Create
- Next by Date: Default item in combobox
- Previous by thread: Re: SQL Server Mobile 3.0 - Out of Memory Exception
- Next by thread: Re: SQL Server Mobile 3.0 - Out of Memory Exception
- Index(es):
Relevant Pages
|