Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MS-Access
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:
 
   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 19-May-13 23:24pm
Edited 20-May-13 1:44am
v2
Comments
CHill60 at 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 at 20-May-13 6:45am
   
Yes, I am using new connection each time, I have added code snippet also.
CHill60 at 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

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 20 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100