?
Solved

ASP.Net print gridview data

Posted on 2013-06-04
12
Medium Priority
?
1,075 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

765 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