Solved

How to prevent the error ["InvalidOperationException" was unhandled. Timeout expired.] when creating multiple Excel files from a C# application using VS2005?

Posted on 2013-01-14
2
583 Views
Last Modified: 2013-01-14
I am developing a C# Windows platform application using VS2005.

The application creates multiple Excel files using a FOR LOOP.

After about 40 Excel files are created my C# application aborts with:

InvalidOperationException was unhandled.

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.

This may have occurred because all pooled connections were in use and max pool size was reached.

I inspected the Windows Task Bar and clicked on the Processes tab:
Under the column titled "Image Name", I see an EXCEL.EXE row for every Excel file the application created. Each of the EXCEL.EXE rows has a memory usage value of about 25,500K.

After 40 Excel files were created, the application aborted and I noticed in Task Manager that 40 rows were created with an Image Name of EXCEL.EXE.

How would I prevent creating a separate EXCEL.EXE for each file generated?

My code is attached in a text file.
ExcelFiles.txt
0
Comment
Question by:zimmer9
  • 2
2 Comments
 
LVL 3

Expert Comment

by:contactnaeem
ID: 38775984
I assumed you are calling BranchToExcel in a look, irrespective of this in BranchToExcel method you opend sqlconnection but did not close. After getting data just close connection and dispose command objects.

Also you created below three objects but never used them just remove these objects if not used or close them propperly.

Excel.Application xlApp;
 Excel.Workbook xlWorkBook;
 Excel.Worksheet xlWorkSheet;
0
 
LVL 3

Accepted Solution

by:
contactnaeem earned 500 total points
ID: 38775985
sorry look=loop
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question