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

I am using C# Application to make the connection with MS-Acces and closing each connection after executing insert and select statements.

But after executing 600-700 times, it is throwing an Execption: "System resource exceeded"


There are no CPU utilization and memory utilization that time.
Also after restarting the application, it works normaly.

Below is the code snippet I am using:

C#
try
         {
             //Setting private fields.
             this.strMdbFile = paramstrMdbFile;
             this.strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Data Source=" + paramstrMdbFile + ";";
             /*Opening connection.*/
             conDBData = new OleDbConnection(strConnString);
             conDBData.Open();

     /* Some statements*/

             conDBData.Close();

         }
         catch (Exception ex)
         {
             string strError = ex.Message;
             MessageBox.Show(strError);
         }
         finally
         {

             if (conDBData != null)
             {
                 if (conDBData.State == ConnectionState.Open)
                 {

                     conDBData.Close();

                 }
             }
         }


Kindly suggest.
Posted
Updated 20-May-13 0:44am
v2
Comments
CHill60 20-May-13 5:42am    
Are you creating a new connection each time and not disposing of them ? Try using the Improve question link above to post some of the code you're using
Vipin_Arora 20-May-13 6:45am    
Yes, I am using new connection each time, I have added code snippet also.
CHill60 20-May-13 6:54am    
Remember to use the Reply link when responding to comments, then the poster will receive notification that you've made a comment

If you use a using statement to wrap all of this then the connection objects should get disposed properly - see http://msdn.microsoft.com/en-us/library/yh598w02.aspx[^]

There's a codeproject article that explains what's going on Understanding the 'using' statement in C#[^]
and here is a good dotnetperls explanation using a database connection (albeit sql not ole)
http://www.dotnetperls.com/sqlconnection[^]
 
Share this answer
 
Did you ever determine what the problem was here?
 
Share this answer
 
Comments
Dave Kreskowiak 24-Nov-14 17:06pm    
Try not to reply to posts over a year old. Start your own thread with your own question.

The problem was more than likely database connection objects not being Disposed when the connection is no longer used.

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