Re: SQL Server Mobile 3.0 - Out of Memory Exception

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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,

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
message
news: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
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




.



Relevant Pages

  • RE: Wrapping Word.Application object with an IDisposable class?
    ... there is an unhandled exception in my program, ... Word process is not closed in Dispose method when the application is tested ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: main form, IDisposable, and Application.Run
    ... exception is thrown between construction and the method call. ... open forms (which would obviously dispose the form). ... Maybe the exception is being thrown from the constructor after all, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: AccessViolationException and Native Exception
    ... dispose a data reader you've already closed or something like that? ... while I prepare the sample you asked me, I send you the exception ... the following exception is thrown: ... and each method opens the connection, ...
    (microsoft.public.sqlserver.ce)
  • Re: Retrieve thrown exception in using (disposable) cleanup
    ... It's generally suggested not to throw exceptions in Dispose: ... class MySession:: IDisposable ... > class MySession: IDisposable ... > already thrown exception as an inner exception in its own exception that ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Native Exception 0xc0000005
    ... Im having a similar problem with the same exception code - mine is also ... Is it possible that some string operation is causing this ... The application some times shows Native Exception: ... The application interects with the SQL Server Mobile database as ...
    (microsoft.public.dotnet.framework.compactframework)