-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EF CORE 9] exec stored procedure really more slow in EF CORE compare to SSMS #35505
Comments
How do you measure the time? Note that the context needs to do significant initialization on the first call after the app is launched, so at the very least start the stopwatch after calling |
@AndriySvyryd this time was mesured with sql server profiler to be at the lower level of the database and exclude all object mapping this kind of stuff. i made a lot a test, each time the stored proc called with entity took 17 second and the same one call through SSMS took 1 second (with the same parameters of course), including the fact i call many time the same procedure in a row, each time i have exactly the same duration. this topic speak exactly of this subject : https://learn.microsoft.com/en-us/answers/questions/90948/stored-procedure-slow-from-application-but-fast-in, but the answer of microsoft is not acceptable. actually after few other research, i understand i can put ARITHABORT ON but not at the sotred procedure level, but more at entity level, what you guys think about that ? thanks |
I try different things but unable to have same performance than SSMS
i also try put this setting directly on the database level following this link https://blog.sqlauthority.com/2018/08/07/sql-server-setting-arithabort-on-for-all-connecting-net-applications/ But same, it change nothing, i think the setting is override because of the Audit Login -- network protocol: LPC which happen each time |
That might be happening because the connection is closed in-between the two calls. Try surrounding your code with these lines: context.Database.OpenConnection(); context.Database.CloseConnection(); |
ok with these lines :
I see in sql server profiler the call to my stored procedure correctly preceded by ARITHABORT ON But it actually change nothing to the performance... so either this parameter is not taken into account either its a totally different problem. Do you have any other suggestions ? |
This doesn't seem to be related to EF, so I don't have enough expertise to be useful. Perhaps you can get help at dotnet/SqlClient#412 or dotnet/SqlClient#2919 |
Indeed it look more a problem in SqlClient than Ef Core, i will check that and see with them if its the case |
Question
Hello guys, i notice big difference in execution time when my call to some stored procedures through my DbContext rather than when i execute them with SSMS.
it took 1 second with SSMS and approx 17 second with the dbcontext.
i found several reference of this issue on internet, some was talking about the ARITHABORT parameter, and generally all was centering about the sniffing problem.
Anyway, nothing of the answers was actually very clear or acceptable, and i didnt find any solution (well, actually i find but was very not recommended to use them) to have my stored proecedure have the same performance than SSMS.
to be precise, there is one request with option(recompile) inside the stored procedure, in case it have impact
So the question, what is the good way to solve this problem ?
thanks for your answer !
Your code
Stack traces
Verbose output
EF Core version
9.0.1
Database provider
Microsoft.entityFramework.SqlServerCode
Target framework
.NET 9.0
Operating system
Windows 11
IDE
Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered: