简体   繁体   English

在 Linux 上运行应用程序时连接到 MSSQL Server 2017 超时

[英]Timeout connecting to MSSQL Server 2017 when application running on Linux

I recently started up an ASP.NET Core Web-Application (WebAPI) using Entity Framework Core for database communications and everything was running really smooth as long as I was running the application on my laptop in my dev environment.我最近启动了一个 ASP.NET Core Web 应用程序 (WebAPI),使用 Entity Framework Core 进行数据库通信,只要我在开发环境中的笔记本电脑上运行该应用程序,一切都运行得非常顺畅。

For hosting the web-app and database I'm using an Ubuntu-server (16.04.3 LTS).为了托管网络应用程序和数据库,我使用的是 Ubuntu 服务器(16.04.3 LTS)。 I installed the latest SQL server (Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)) and I can connect to it from my application just fine as long as the application is running on windows.我安装了最新的 SQL 服务器(Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)),只要应用程序在 Windows 上运行,我就可以从我的应用程序连接到它。 However, using the same code and connection string on Ubuntu all queries just time out.但是,在 Ubuntu 上使用相同的代码和连接字符串,所有查询都会超时。 I get the following output (exception/stacktrace):我得到以下输出(异常/堆栈跟踪):

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HL6RV4D2F9I6": An unhandled exception was thrown by the application.
System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: Unknown error 258
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   at System.Data.SqlClient.TdsParserStateObject.TryReadByteArray(Byte[] buff, Int32 offset, Int32 len, Int32& totalRead)
   at System.Data.SqlClient.TdsParserStateObject.TryReadChar(Char& value)
   at System.Data.SqlClient.TdsParser.TryReadPlpUnicodeCharsChunk(Char[] buff, Int32 offst, Int32 len, TdsParserStateObject stateObj, Int32& charsRead)
   at System.Data.SqlClient.TdsParser.TryReadPlpUnicodeChars(Char[]& buff, Int32 offst, Int32 len, TdsParserStateObject stateObj, Int32& totalCharsRead)
   at System.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly)
   at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
   at Microsoft.EntityFrameworkCore.Storage.Internal.UntypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func`2 operation, Func`2 verifySucceeded, TState state)
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at lambda_method(Closure , QueryContext )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass20_0`1.<CompileQueryCore>b__0(QueryContext qc)
   at System.Linq.Queryable.First[TSource](IQueryable`1 source, Expression`1 predicate)
   at Considition.WebAPI.Controllers.GameController.InitiateGame(String apikey) in /home/fredrik/WebApps/Considition/Considition.WebAPI/Controllers/GameController.cs:line 70
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
ClientConnectionId:19a604ef-758e-4797-8780-6b95dcbfdd17
Error Number:-2,State:0,Class:11
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 35515.1854ms 500

The line in my code where the exception occurs is:我的代码中发生异常的行是:

var teamGameState = ctx.GeneratedGameStates.First(x => x.TeamId == teamId);

The table only has one entry and looking at the Activity Monitor in SSMS, I can see that the translated SQL is something like (SELECT TOP 1 * FROM ...) and that the query is taking 35 seconds.该表只有一个条目,查看 SSMS 中的活动监视器,我可以看到翻译后的 SQL 类似于 (SELECT TOP 1 * FROM ...) 并且查询需要 35 秒。

I've been reading about other people having a similar issue when trying to connect to the SQL Server from Linux with the same code that was working fine from windows, but I could not find a solution.我一直在阅读有关其他人在尝试使用在 Windows 中运行良好的相同代码从 Linux 连接到 SQL Server 时遇到类似问题的信息,但我找不到解决方案。

Is anyone else experiencing this issue and more importantly did someone solve it?有没有其他人遇到过这个问题,更重要的是有人解决了这个问题吗?

I think this is a duplicate of: https://github.com/aspnet/EntityFrameworkCore/issues/5989我认为这是重复的: https : //github.com/aspnet/EntityFrameworkCore/issues/5989

Solution there: update the server software, because you are on RC2.那里的解决方案:更新服务器软件,因为您使用的是 RC2。

I recently started up an ASP.NET Core Web-Application (WebAPI) using Entity Framework Core for database communications and everything was running really smooth as long as I was running the application on my laptop in my dev environment.我最近启动了一个 ASP.NET Core Web 应用程序 (WebAPI),使用 Entity Framework Core 进行数据库通信,只要我在开发环境中的笔记本电脑上运行该应用程序,一切都运行得非常顺畅。

For hosting the web-app and database I'm using an Ubuntu-server (16.04.3 LTS).为了托管网络应用程序和数据库,我使用的是 Ubuntu 服务器(16.04.3 LTS)。 I installed the latest SQL server (Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)) and I can connect to it from my application just fine as long as the application is running on windows.我安装了最新的 SQL 服务器(Microsoft SQL Server 2017 (RC2) - 14.0.900.75 (X64)),只要应用程序在 Windows 上运行,我就可以从我的应用程序连接到它。 However, using the same code and connection string on Ubuntu all queries just time out.但是,在 Ubuntu 上使用相同的代码和连接字符串,所有查询都会超时。 I get the following output (exception/stacktrace):我得到以下输出(异常/堆栈跟踪):

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HL6RV4D2F9I6": An unhandled exception was thrown by the application.
System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: Unknown error 258
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   at System.Data.SqlClient.TdsParserStateObject.TryReadByteArray(Byte[] buff, Int32 offset, Int32 len, Int32& totalRead)
   at System.Data.SqlClient.TdsParserStateObject.TryReadChar(Char& value)
   at System.Data.SqlClient.TdsParser.TryReadPlpUnicodeCharsChunk(Char[] buff, Int32 offst, Int32 len, TdsParserStateObject stateObj, Int32& charsRead)
   at System.Data.SqlClient.TdsParser.TryReadPlpUnicodeChars(Char[]& buff, Int32 offst, Int32 len, TdsParserStateObject stateObj, Int32& totalCharsRead)
   at System.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly)
   at System.Data.SqlClient.SqlDataReader.GetValues(Object[] values)
   at Microsoft.EntityFrameworkCore.Storage.Internal.UntypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func`2 operation, Func`2 verifySucceeded, TState state)
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at lambda_method(Closure , QueryContext )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass20_0`1.<CompileQueryCore>b__0(QueryContext qc)
   at System.Linq.Queryable.First[TSource](IQueryable`1 source, Expression`1 predicate)
   at Considition.WebAPI.Controllers.GameController.InitiateGame(String apikey) in /home/fredrik/WebApps/Considition/Considition.WebAPI/Controllers/GameController.cs:line 70
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
ClientConnectionId:19a604ef-758e-4797-8780-6b95dcbfdd17
Error Number:-2,State:0,Class:11
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 35515.1854ms 500

The line in my code where the exception occurs is:我的代码中发生异常的行是:

var teamGameState = ctx.GeneratedGameStates.First(x => x.TeamId == teamId);

The table only has one entry and looking at the Activity Monitor in SSMS, I can see that the translated SQL is something like (SELECT TOP 1 * FROM ...) and that the query is taking 35 seconds.该表只有一个条目,查看 SSMS 中的活动监视器,我可以看到翻译后的 SQL 类似于 (SELECT TOP 1 * FROM ...) 并且查询需要 35 秒。

I've been reading about other people having a similar issue when trying to connect to the SQL Server from Linux with the same code that was working fine from windows, but I could not find a solution.我一直在阅读有关其他人在尝试使用在 Windows 中运行良好的相同代码从 Linux 连接到 SQL Server 时遇到类似问题的信息,但我找不到解决方案。

Is anyone else experiencing this issue and more importantly did someone solve it?有没有其他人遇到过这个问题,更重要的是有人解决了这个问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MSSQL Server:正在运行存储过程 - MsSql server:running stored procedure 从 Linux 主机连接到 SQL 服务器时,远程证书被拒绝 - Remote certificate rejected when connecting to SQL Server from Linux host VS2017上的SQL Server连接超时 - SQL Server connection timeout on VS2017 从Windows .NET服务器连接到运行MySQL的Linux服务器,ADO.NET? - Connecting to a linux server running MySQL from a windows .NET server, ADO.NET? 在Visual Studio 2017中创建安装项目(带有MSSQL Server数据库) - Create Setup Project in Visual Studio 2017 (with MSSQL Server Database) 点网核心–如何解决:MSSQL 2017超时错误(.Net 4.7.1不会发生) - Dot net Core – How to fix: TimeOut-Error to MSSQL 2017 (which does not happen with .Net 4.7.1) 在MVC5.net应用程序中请求角色时,SQL Server超时 - SQL Server timeout when requesting roles in MVC5.net application 连接到SQL Server Express 2012的超时 - Timeout connecting to SQL Server Express 2012 在C#中连接到AWS Managed SFTP服务器时SSH.NET超时 - SSH.NET timeout when connecting to AWS Managed SFTP server in C# 连接到服务器时的SocketException - SocketException when connecting to server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM