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
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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Did you ever determine what the problem was here?
  Permalink  
Comments
Dave Kreskowiak at yesterday
   
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)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 273
2 Aajmot Sk 224
3 Marcin Kozub 210
4 Richard MacCutchan 200
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 24 Nov 2014
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