DataTable Load very slow
Not the best thread I've seen on the issue, but there's good links inside, & it's in my post history:
SQL Query that runs fine in SSMS runs very slow in ASP.NET
The SQL Optimizer sometimes likes to decide what's best & you'll have to break out your query through some tracing and logging of data execution plans. It may very well be something as buried as a bad index, or your query code might need optimization. Seeing as we don't have the query code, and having it may or may not be helpful. I'd recommend you follow the guides linked to in the above post and close your question.
Related videos on Youtube
jimmy
Updated on September 27, 2022Comments
-
jimmy over 1 year
I'm using a datatable as the datasource of some dropdowns on a page, but have noticed that the page is very slow during the postbacks.
I've tracked it through to here:
DataTable dt = new DataTable(); dt.Load(sqlCmd.ExecuteReader()); // this takes ages
The sql command is a parametrised query, not a stored procedure (the return values and where are quite 'dynamic' so this wouldn't be practicable), but nevertheless a simple select union query. Usually returns between 5 and 20 options per dropdown, depending on what's been selected on the other dropdowns. When I run the query in the management studio, it's done in under a second. Here it can take up to 7 seconds per dropdown, with 6 dropdowns on the page it soon adds up. I have also tried with a SqlDataAdapter:
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd); sqlDa.Fill(dt); // this takes ages
but this was just as slow. I have this on 2 different systems and on both have the same performance issues.
If anyone knows a better (faster) methord, or knows why this is so slow that would be great.
-
Tim Schmelter about 11 yearsA little bit more context and code please. Where is the code located, is anything static, is the page also slow on your development server with a single user?
-
-
jimmy about 11 yearsSo I finally found the issues, someone had deleted my indexes. I re-added them and everything ran quickly again. Why this was only causing performance issues in c# and not SSMS I will leave to greater mindes
-
RandomUs1r about 11 yearsSSMS caches your queries, the first time it probably ran slow, and then fast every time since making it difficult to replicate the problem.
-
MC9000 about 2 yearsYour second example is much faster due to Load method being appallingly slow.