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
580 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
Comment Utility
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
Comment Utility
sorry look=loop
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now