Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have .Net CF 3.5 C# console application on Win CE 6.0 R3 OS and ARM 4i processor with 64 MB RAM and Sql CE 3.5 database in my device.

I am using 3 tier architecture 1. My project, 2. BLL 3. DAL.

In DAL ,I am only Creating an Object of SqlCeConnection , Object.Open() and Object.Close() and in finally block Object.Dispose() without making any transaction or executing any queries. Find below code snippet.

C#
public static void OpenCloseConn()
{
SqlCeConnection _myConnection = null ;
try
{
lock (_executeScalar)
{
using (_myConnection = new SqlCeConnection("Getting Connection String from App.config"))
{
_myConnection.Open();
 
_myConnection.Close();
}
}
}
catch(...){ }
finally
{
if (_myConnection.State != ConnectionState.Closed)
_myConnection.Close();
_myConnection.dispose();
}
}


From my app I am calling the above code snippet infinitely via BLL to DAL in a while loop to check Memory leak issue. also used devhealth60 tool for memory snapshot and observed that every 2-2.5 Min some 5 kb(without executing any query like select,insert...) of heap memory of my application increases so as physical memory but not increasing the available virtual memory.

Kindly suggest me how to deal with Sql CE 3.5 database in .Net CF without any memory leak as I have very frequent use of .sdf database file from 3 diff apps in my entire project and all apps are never ending so after 1-2 days it stops functioning, required hard reboot.

I am calling above code from my app as below:

C#
while(true)
{
BLLClass.Instance.OpenCloseSqlCEConnection();
}
 
In BLL:
 
public void OpenCloseSqlCEConn()
{
DALClass.Instance.OpenCloseSqlCEConn();
}
 
In DAL:
public void OpenCloseSqlCEConn()
{
DBHelp.OpenCloseConn(); // method present in DBHelp(class for all Database operaions) class
}



Any help will be appreciated.

Thanks in advance,

Vijay

====EDIT: Please Use Code tags====
CodingK
Posted
Updated 24-Nov-14 3:24am
v4
Comments
[no name] 21-Nov-14 15:47pm    
The SQL CE database is Depreciated as far as I can recall, so you might be best using some other supported database type.

Using blocks should dispose of its own resources used by those code blocks; so no point checking the connection state in this case.

What is the While loop you are mentioning above? Can you explain a little further, and show more code by updating your question, as there may be other causes for your issue.
Member 10814246 24-Nov-14 1:01am    
I have updated my question. Kindly look at once
[no name] 24-Nov-14 9:28am    
See answer below. Please also use code tags when posting code, I've edited your question for you this time.

1 solution

It is highly unlikely you will have memory leaks in .net and most certainly Microsoft will have tested interoperability issues with SqlCe and .net

Memory usage is natural in .net, and the CLR will free unused memory in the next GC cycle so you should not worry about it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900