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
587 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

687 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