Time taking Asp.Net GridView with 2 million Records - asp.net

I did a task which geting more than 2 millions record from sqlserver and populate them in Asp.net GridView.
The problem is that, query taking more than 2 minutes in getting record while my query is now fully optimized.
when i move from one page to another by pagination it take again same time and hit server.
so i need a solution where its not take time during page movement or get only 50 or 100 record in each request.
Thanks,
Nauman

Use paging in GridView - check this link
Also adjust display property like display header with available visible cells to load the grid faster.
Its even better if you bind the grid data using jQuery and not from server side.
Use this link to get started
Instead of using GridView you can use repeater or even jQuery templates also with custom paging. that'll be even more fast.

if you are fetching 1000 records and displaying just 50 using pagination, this is really a waste. better to display 50 records each time, this would be much faster. go through the following link:Custom Paging in ASP.Net GridView using SQL Server Stored Procedure

it's problem on sqlserver...
optimization the data base,separate the database and the table

Related

Grid loading too slow with out pagination

We have developed Asp.net web application. and we are using asp.net gridview to display the records and edit.
here we have 5000 rows and 23 columns in single grid. it is taking long time for binding. our client refuse the pagination option. how to make the binding faster with 5000 to 7000 records.
Please Advise.
Thanks
Mayil.M
Where is your data come from? Is it database or other external resource?
You can use caching so you don't load the whole dataset from the external resource but from the memory. Please note this solution will not work if your data changes often.
Another approach would be to use some kind of partial loading mechanism using for example Ajax. This will however require changing approach as I am not sure the grid view control supports this. You would have to create custom control and then make sequential requests (using for example Ajax) for smaller chunks (eg. 200 records) of data and display them. Eventually you will have complete set but the data will be available faster.
Finally you can combine both, to make it even faster.
You should implement your own paging mechanism. The problem is that DataBind retrieves all 7000 records (although only i.e. 20 is displayed/rendered). Create for example a stored procedure that will fetch only selected range of records (if you are on Page 2 you need to display only record id > 20 and <= 40 - considering that your pagesize is 20). Use SQL server CTE to get the row number (on SQL Server side) and features like BETWEEN. This stored procedure would return only those records which you really need to. Then change your grid view to get the data from this stored procedure.
You can load data on scroll like facebook wall.

Display Paging In ASP.NET GridView Even with a single Page

In My Database I Have 10000000 Records. In GridView First I Am Showing First 10 Records. In Order To See the Next Records User Need to Click Page Numbers ( 1,2,3,------10000). But As I'm Retrieving 10 Records for The First Time GridView Paging is not Showing.
Is There Any Way To Show Paging In ASP.NET GridView Statically ?
For so many records, I won't recommend Paging. You can show Top 20 recently added records and provide options to filter out records. A user can enter keywords. ReQuery and ReBind the GridView with this new result set.
You might also consider using PetaPoco, a Micro-ORM, which will help you fetch paged result.
With so many records, you really need to take into account the exact queries being run to pull back the data.
There are numerous ways of doing data paging ( http://beyondrelational.com/modules/2/blogs/28/posts/10434/sql-server-server-side-paging-with-rownumber-function.aspx ). However, the "best" way is dependent on the exact version of SQL Server you are running.
Essentially, the solutions boil down to you passing a page number and number of records per page through some type of query. Usually a stored procedure as the query can be quite messy.
Once there, you have an option. Either send the total record count back as an OUT parameter in your query and the result set back normally, or you send the total record count back as a column. There are definitely efficiency concerns with both options as one way requires the query to be run twice and the other requires an extra column of data which increases network traffic.
Once you have that solved then you can figure out exactly how you want the UI to work.

Performance issue in Getting report using gridview from tables and view in SQL server

I have a database which has some table and every one of them has at least 100000 records.
I need to show reports of these data to admin of asp site so I have used views to join these table to get my required info to show. but the problem is when I run the page although it should show just 10 records for first page and other records can be lazy, it become time out because it takes so long time to make view and show in gridview.
Is there any way to handle this problem?
for example If I can make these joins for view when sql server is idle it will improve performance issue. But I don't know is it possible or not
hi how about using paging and loading data on request in gridview i mean here is an example hope this might help you:
Loading data on request and paging
I recommend you to use custom paging in you sql query

asynchronous processing in asp.net

on my page load I am loading few list, also on my page I have filter conditions which is taking around 30 seconds to get the filtered records from the database, reason : Database is big and I have to navigate to 9 tables to get the list of records depending upon the selected values.
What is the simplest way to achieve asynchronous processing ?
How are you structuring your SQL? If you have to access 9 tables it seems like a view would be a more appropriate solution than joining 9 tables.
When you page load is finished, d an ajax call with jquery to a service. That services generates the output html that you need. You can place a loader in the div/table where the table is going to be displayed
Maybe you should refactor your query, 30 seconds is really long. Are you using keys, indexes, temp tables, full text searches, ect ect to optimize your query

How do I maintain the data in my gridview beyond postback?

I'm writing an internal web application that is used to look up credit checks. I'm using ASP.NET for this website.
I have a SQL Query that I have to query the credit check database and it returns a datatable of results. After the person clicks search, I run the query and bind the returned datatable to the Gridview every time the user clicks the search button.
This works fine, and it populates my gridview like it should.
How do I maintain the data that is bound to my gridview beyond postback? For example, lets say a person clicks Page 2 of the paginated gridview... how do I keep from losing the data of the gridview during that postback?
Currently I am storing the datatable in session[] but I don't think I should be doing this, because the size of this table is very large (sometimes hundreds of thousands of results!)
Do I need to re-query the database for each postback? The query takes a decent bit and I'd rather not if I could help it.
What is the common solution here?
If you are storing the data in the session I would make sure viewstate is turned off and you are rebinding it on each postback so at least your not storing all that data in 2 places.
You could also considered leaving the viewstate on and changing logic that grabs the session data to bring back one page of data at a time? You would take in the current page and JUST return that page's data so that you could get all the data at first and store it in the session. Then if any other postback actions occurred during that page view where nothing was really going on with the grid you wouldn't have to rebind each time.
I have found that most of the issues I have run across in the past due to too much data being displayed in a grid were more design issues and I would step back and look at the overall problem that was trying to be solved and implement another solution to not have to display so much data. Usually a customer/user asks for everything because they don't consider any alternatives or the impact of their request.
Several things:
Clicking on "Page 2" should not result in a postback - it should be a simple GET request.
Do not allow GridView to store its data in the ViewState: cache data manually and "rebind" datasource on each request
Use ASP.NET MVC

Resources