My issue started with Entity Framework
query executing very slowly (~2 minutes). So I started investigating
Meanwhile it seems the issue is also in standard SqlConnection
I have a pretty simple query
SELECT 1 AS [C1], [Extent1].[OldReleaseID] AS [OldReleaseID], [Extent1].[ProductName] AS [ProductName], [Extent1].[Price] AS [Price], [Extent1].[DiscountAmount] AS [DiscountAmount], [Extent1].[DiscountRate] AS [DiscountRate], [Extent1].[AbsorbVat] AS [AbsorbVat], [Extent1].[SerialCode] AS [SerialCode], [Extent1].[BrandName] AS [BrandName] FROM [dbo].[LocalSaleProductExts]() AS [Extent1]
When I run it in SSMS
it executes in 0-1 seconds and returns about 30k rows
The same precise query runs in .net ExecuteReader
about 100 seconds!
Online research points to basically 2 solutions: ARITHABORT and parameter sniffing, so for kicks, i added all this in SSMS
DBCC FREESESSIONCACHE
DBCC FREEPROCCACHE
SET ARITHABORT OFF
Still 0-1 seconds.
And in my code I added SET ARITHABORT ON
. Here's my simple code
Using sc = New SqlClient.SqlConnection("data source=MYHOST;initial catalog=MYDB;persist security info=True;user id=MYUSER;password=MYPASS;MultipleActiveResultSets=True;")
Dim txt = "SELECT 1 AS [C1], [Extent1].[OldReleaseID] AS [OldReleaseID], [Extent1].[ProductName] AS [ProductName], [Extent1].[Price] AS [Price], [Extent1].[DiscountAmount] AS [DiscountAmount], [Extent1].[DiscountRate] AS [DiscountRate], [Extent1].[AbsorbVat] AS [AbsorbVat], [Extent1].[SerialCode] AS [SerialCode], [Extent1].[BrandName] AS [BrandName] FROM [dbo].[LocalSaleProductExts]() AS [Extent1] OPTION (RECOMPILE)"
sc.Execute("SET ARITHABORT ON")
sc.TryOpen()
Dim ret As List(Of Common.DbDataRecord)
Using cmd = sc.CreateCommand(txt)
Using dr = cmd.ExecuteReader
ret = dr.Cast(Of Common.DbDataRecord).ToList
dr.Close()
End Using
End Using
Dim a = ret
End Using
Parameter sniffing I believe is irrelevant here, since I'm not sending any parameters
Neither is it a blocking issue, since I'm testing them at the same time (as much as humanly possible...), so if it's a timing issue, both should be slow
So what else can the issue be?
Thanks so much