Solved

ASP.Net print gridview data

Posted on 2013-06-04
12
1,039 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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