How-to-simply...

Fix ADO.NET slow query performance while the same query runs fast in SSMS

  • 1 Check ARITHABORT ON/OFF setting on SQL Server:
    /* TEST FOR ARITHABORT ON */
    DECLARE @options TABLE ([name] nvarchar(35), [minimum] int, [maximum] int, [config_value] int, [run_value] int);
    INSERT INTO @options ([name], [minimum], [maximum], [config_value], [run_value])
    EXEC sp_configure 'user_options';
    SELECT [setting] = 'ARITHABORT ' + CASE WHEN ([config_value] & 64) = 64 THEN 'ON' ELSE 'OFF' END
    FROM @options;
    GO
  • 2 Set ARITHABORT ON globally on single database when it is turned OFF:
  • 3 USE [master]
    GO
    IF (EXISTS (SELECT * FROM sys.databases db WHERE db.[name] = N'{DbName}' AND db.[is_arithabort_on] = 0))
    BEGIN
    --ALTER DATABASE [{DbName}] SET ARITHABORT ON WITH NO_WAIT;
    END
  • N Beware that changing this setting may break some existing applications. Read the documentation first: https://docs.microsoft.com/en-us/sql/t-sql/statements/set-arithabort-transact-sql?redirectedfrom=MSDN&view=sql-server-ver15

References