ASP.Net print gridview data

I have the need in a web application to print gridview data that is displaying on the screen. Currently I am adding the gridview as part of a HTML form to open a new page and add other text to the page. For example, I add the current date, grid name, and query parameters so they can see these on the printed page.

This all seems to work when the dataset is small. However when the dataset grows to about 2000 records, the page occasionally times out before loading. Is there a better way to export data to be printed so it doesn't time out?

I am getting the error "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 has been reached."  Unless building the gridview is taking all pooled connections, which I have at 300, it should not be using all of the connections. This is an internal website that currently is very low in use, no more than 2 or 3 concurrent users as we are not completely in production. It has happened in development when I know that I was the only user. I think that the page may be timing out.

Any help will be greatly appreciated.
LVL 18
Jerry MillerAsked:
Who is Participating?
 
Roopesh ReddyIT AnalystCommented:
Hi,

May be pulling the records from the Database is the culprit! You can also try Stored Procedures instead of direct SQL queries against the database!

You can try this!

Moreover, while rebinding, are you fetching the records again from database?
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

First of all, don't load all the records at once to the Grid. Use Pagination.

While printing you can print all the records - http://www.aspsnippets.com/articles/print-functionality-in-asp.net-gridview-control.aspx

Hope it helps u...
0
 
Jerry MillerAuthor Commented:
I am turning off paging to print everything at once. In my RowDataBound event, I am binding a small repeater that contains multiple records for each row. The repeater only has a few records for each one, 1-3, but this seems to be slowing it down drastically.

I used the example in your post, but I think that the nested repeater is killing me. Any suggestions on how to show the data that I am displaying i the repeater?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Roopesh ReddyIT AnalystCommented:
Hi,

You should be considering nested GridView - http://csharpdotnetfreak.blogspot.com/2012/06/nested-gridview-example-in-aspnet.html

Hope it helps u...
0
 
Jerry MillerAuthor Commented:
I have tried various approaches to this including the nested gridviews. I am currently still using the repeater nested in the gridview. It works most of the time, but occasionally times out. I am trying to eliminate all time out issues as my users need to run reports for time periods of months, quarters, etc.

I tried caching the gridview datasource but in order to turn off paging, I have to rebind which is where the slowness occurs.
0
 
Jerry MillerAuthor Commented:
roopeshreddy, I am using stored procedures.

Yes on my rebind I am going back to the database. I tried caching the datasource, but in order to turn off paging I had to rebind which I believe is causing my issue. The gridview loads in about 2 seconds with paging on, but sometimes times out with it off for printing.

What I don't understand is that it works fine sometimes. There could be an issue with one of the web servers or one of the database servers, but unless I can point to one of them with an actual error neither of the groups responsible for them will look at it. There are 4 web servers in a load balanced set up and 2 database servers in a clustered environment.
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

Yeah! You have to nail down the issue by looking at the Load balancing servers!
0
 
Jerry MillerAuthor Commented:
I added some indexes to my SQL tables based on the query optimizer and it solved my issue.
0
 
Jerry MillerAuthor Commented:
Led me in the right direction.
0
 
Jerry MillerAuthor Commented:
As another piece to the puzzle for anyone reading this thread.

I had a small repeater that was being data bound via a separate stored procedure and it was slowing the print function. I removed the repeater and added that information as a join in the original stored procedure.

This provides some extra rows instead of having each line with the invoice number and then a repeater for each sub amount. Any invoice that has multiple sub amounts will have additional rows. Which is not a huge problems since now the report runs every time.
0
 
Roopesh ReddyIT AnalystCommented:
Hi,

Since this post is answered, you can start a new thread!
0
 
Jerry MillerAuthor Commented:
I was only adding more information about the solution to the issue not asking how to fix it. The problem is resolved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.