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
581 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

861 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

26 Experts available now in Live!

Get 1:1 Help Now