Click here to Skip to main content
11,795,568 members (77,337 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# MS-Access

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:

             //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);
     /* Some statements*/
         catch (Exception ex)
             string strError = ex.Message;
             if (conDBData != null)
                 if (conDBData.State == ConnectionState.Open)

Kindly suggest.
Posted 19-May-13 22:24pm
Edited 20-May-13 0:44am
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
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[^]

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

Solution 2

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

  Print Answers RSS
0 Maciej Los 340
1 Sergey Alexandrovich Kryukov 316
2 OriginalGriff 285
3 Abhinav S 223
4 KrunalRohit 214
0 OriginalGriff 1,797
1 Maciej Los 1,415
2 KrunalRohit 1,240
3 CPallini 840
4 ppolymorphe 808

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 24 Nov 2014
Copyright © CodeProject, 1999-2015
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