简体   繁体   中英

Why is a call to DatabaseInstance.ExecuteSprocAccessor<T>(…) taking so long for such a simple query?

Very odd slowdown when calling the Data Access Application block.

The SP ("QuestionsToBeAnswered") it's calling returns 58 rows with three columns (two GUIDs and an integer: 21AF77DA-2E76-47DB-AB54-0E5C85CD9AD8, 21AF77DA-2E76-47DB-AB54-0E5C85CD9AF0, 2) in less than 1 second when executed directly on the server. My SQL experience is pretty good, and I'm convinced the problem doesn't exist on the SQL server.

However, when it's called through DAAB, it's taking a very long time to return the collection of objects. ExecuteSprocAccessor(...) normally returns an IEnumerable, and the SP isn't executed until the collection is enumerated or otherwise consumed, so this problem doesn't show up until consumption occurs.

DatabaseInstance.ExecuteSprocAccessor<T>(storedProcedure, rowMapper, args);

Given that the same code has no problem returning >200 rows of considerably more complex information, I am baffled as to why this code is taking so long (55 seconds!) to execute.

Any ideas would be welcomed...

You could try running SQL Profiler to see what the actual call looks like when it run using DAAB. With that in hand take a look at the execution plan that it is using.

In the past I wrote some code that ran fine as a SQL query but was really slow as a stored procedure. Turns out do to some duplicate indexes the query optimizer was using a different execution plan for the SQL Query then the stored procedure. After getting the indexes sorted both ran at the same quick speed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM