Solved

ASP.Net print gridview data

Posted on 2013-06-04
12
1,010 Views
Last Modified: 2013-07-31
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.
0
Comment
Question by:Jerry Miller
  • 7
  • 5
12 Comments
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 39223024
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
 
LVL 18

Author Comment

by:Jerry Miller
ID: 39224027
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
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 39225698
Hi,

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

Hope it helps u...
0
 
LVL 18

Author Comment

by:Jerry Miller
ID: 39235149
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
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 500 total points
ID: 39249454
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
 
LVL 18

Author Comment

by:Jerry Miller
ID: 39253198
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 39253689
Hi,

Yeah! You have to nail down the issue by looking at the Load balancing servers!
0
 
LVL 18

Author Comment

by:Jerry Miller
ID: 39353113
I added some indexes to my SQL tables based on the query optimizer and it solved my issue.
0
 
LVL 18

Author Closing Comment

by:Jerry Miller
ID: 39353120
Led me in the right direction.
0
 
LVL 18

Author Comment

by:Jerry Miller
ID: 39371474
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
 
LVL 23

Expert Comment

by:Roopesh Reddy
ID: 39372030
Hi,

Since this post is answered, you can start a new thread!
0
 
LVL 18

Author Comment

by:Jerry Miller
ID: 39372078
I was only adding more information about the solution to the issue not asking how to fix it. The problem is resolved.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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