'MS SQL SERVER connection timout on different schema on same server

'''

    Try
        Dim connectionString As String = "Server=" & SERVER_NAME & ";Database=" & DB_NAME & ";User Id=" & USER_ID & ";Password=" & PASSWORD_STRING
        Using conn As New SqlConnection(connectionString)
            conn.Open()
            Using adapter As New SqlDataAdapter("SELECT * FROM CUSTOM_VIEW", conn)

                adapter.Fill(dtCustom_view)

            End Using
        End Using
    Catch ex As Exception
        Console.WriteLine(ex)
        Console.WriteLine("Press any key...")
        Console.ReadKey()
        Environment.Exit(0)

    End Try

'''

Problem is when connection is made to DB_NAME="One" works fine, when DB_NAME="Two" exeption is rised

Both schemas are on the same server. I can connect to both schemas using ODBC with same username and password. Problem rised after user have upgraded SQL server to compatibility level 2019. Prior it was 2008 and there were no problem to connect to both schemas.

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at iSAF.Module1.Main(String[] args) ClientConnectionId:ba3bf0f6-683d-4394-9d4d-43948269e5da Error Number:-2,State:0,Class:11



Solution 1:[1]

Problem rised after user have upgraded SQL server to compatibility level 2019. Prior it was 2008 and there were no problem to connect to both schemas.

You should turn on Query Store to gather query performance baselines before increasing the compatibility level.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Browne - Microsoft