首页 > 数据库 >.Net 5.0 程序在 Linux 环境访问 SqlServer 2008R2 莫名报错:Connection reset by peer

.Net 5.0 程序在 Linux 环境访问 SqlServer 2008R2 莫名报错:Connection reset by peer

时间:2023-11-03 13:34:00浏览次数:40  
标签:5.0 reset DbConnectionOptions TdsParserStateObject SqlClient Boolean 报错 Data Mic

〇、问题详情

同样的代码,在 Windows 上运行的好好的,拿到 CentOS 7 上运行就出现如下报错:

【ex.message】:A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught)

【ex.InnerException】:System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.

报错详情堆栈等信息
【ex.message】:A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 35 - An internal exception was caught)
【ex.InnerException】:System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer.
 ---> System.Net.Sockets.SocketException (104): Connection reset by peer
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at Microsoft.Data.SqlClient.SNI.SNIPacket.ReadFromStream(Stream stream)
   at Microsoft.Data.SqlClient.SNI.SNITCPHandle.Receive(SNIPacket& packet, Int32 timeoutInMilliseconds) 
【ex.StackTrace】:   at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.InitializeReader(DbContext _, Boolean result)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementation[TState,TResult](Func`3 operation, Func`3 verifySucceeded, TState state)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
   at xxxxxx.Operation() in E:\xxxxxxxxxxx.cs:line 149

一、问题原因与解决办法

Linux 访问 Windows 上的 SqlServer 数据库,需要 SqlServer2008 SP3 或以上版本。

然后解决起来就比较简单了,首先可以先打补丁,或者在 SqlServer 2008 R2 的基础上直接升级至 SqlServer 2012 或更高版本,下面就分别介绍下两种方法。

1.1 给 SqlServer 2008 R2 打补丁 SP3

注意:打补丁过程中可能造成数据库临时停用,需关注业务影响。

1.1.1 下载补丁安装包以及前置报错处理

在官网下载好补丁 SP3:https://www.microsoft.com/zh-CN/download/details.aspx?id=44271

然后需要保证当前数据库可以正常操作,避免出现如下图中的错误提示,不然 SP3 安装包可能会一开始就验证失败:

上边图片中的报错解决办法就是:新增如下像个文件夹:

1.1.2 安装 SP3 的步骤

双击安装包:

下一步:

接受,下一步:

下一步:

根据提示可以手动停止服务:SQL Server (MSSQLSERVER),如果没有提示,就直接下一步:

更新:

更新需要十分钟左右,更新完成关闭窗口即可:

通过select @@version查询数据库版本信息如下:

Microsoft SQL Server 2008 R2 (SP3) - 10.50.6000.34 (X64)   Aug 19 2014 12:21:34   Copyright (c) Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 17763: ) (Hypervisor) 

至此更新完成!

1.2 从 2008 R2 升级至 2012 版本

注意:先备份,再升级!

1.2.1 下载 SqlServer 2012 数据库安装包

官网下载地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=35575

本文以安装包 SQLServer2012SP1-FullSlipstream-CHS-x64.iso 为例。

1.2.2 安装步骤

从 SQL Server 2008 R2 升级到 SQL Server 2012 SP1,需要先安装 SQL Server 2008 R2 的 SP1 或 SP2 补丁包,补丁安装步骤可参考本文 1.1。

提供一个经验证可用的 2012 SP1 密钥:FH666-Y346V-7XFQ3-V69JM-RHW28

安装步骤请参阅博友文章:https://www.cnblogs.com/wangfuyou/p/5962025.html

标签:5.0,reset,DbConnectionOptions,TdsParserStateObject,SqlClient,Boolean,报错,Data,Mic
From: https://www.cnblogs.com/hnzhengfy/p/DotnetToLinux.html

相关文章

  • kubenetes 报错排查
    1.报code=Unknowndesc=failedtogetsandboxip:checknetworknamespaceclosed:removenetns:unlinkat/var/run/netns/cni-2502ee8a-9f06-2a44-66c6-59e2a7a277f9:deviceorresourcebusy解决方案:seecode=Unknowndesc=failedtogetsandboxip:chec......
  • 采坑-阿里云 kex_exchange_identification: read: Connection reset by peer
    自己买了台阿里的测试服务器,打开终端,输入命令 sshroot@xxx 等待输入密码。**报错:kex_exchange_identification:read:Connectionresetbypeer******昨天刚用的,今天咋回事,然后试了试公司的服务器是可以的。然后就开始百度找资料,找了一圈,大部分都是让修改配置文件。但是换了......
  • 启动nginx报错nginx: [emerg] unexpected end of file, expecting "}" in /usr/local/
    启动nginx报错:“nginx:[emerg]unexpectedendoffile,expecting“}”in/usr/local/nginx/conf/nginx.conf:118”重启nginx时,报这么个错:[root@localhostconf]#/usr/local/nginx/sbin/nginx-sreloadnginx:[emerg]unexpectedendoffile,expecting“}”in/usr/lo......
  • 【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext'
    问题描述AzureWebJob执行Powershell脚本报错 Select-AzContext:Theterm'Select-AzContext'isnotrecognizedasthenameofacmdlet,function,scriptfile,oroperableprogram.Checkthespellingofthename,orifapathwasincluded,verifythatthepa......
  • nginx报错 [error] 612#4188: CreateFile() "C:\yjzx\nginx-1.24.0/logs/nginx.pid"
    背景无论是nginx-sstop还是nginx-sreload命令,都会出现这个错误。[error]612#4188:CreateFile()"C:\yjzx\nginx-1.24.0/logs/nginx.pid"failed(2:Thesystemcannotfindthefilespecified)查找logs下nginx.pid文件确实没有创建成功,在网上查找了下了解决办法。发......
  • yum install 报错Error downloading packages
    yuminstallntp报以下错误:Errordownloadingpackages:autogen-libopts-5.18-5.el7.x86_64:[Errno5][Errno2]Nosuchfileordirectoryntp-4.2.6p5-29.el7.centos.2.x86_64:[Errno5][Errno2]Nosuchfileordirectoryntpdate-4.2.6p5-29.el7.centos.2.x86_64:......
  • 阿里云服务器 ubuntu 20.04 执行命令添加apt仓库时报错 安装docker报错
    云服务器ECS初始安装docker报错##############出错时候看下面#####################执行命令添加apt仓库时:sudoadd-apt-repositoryppa:ondrej/php&&sudoapt-getupdate报错:sudo:add-apt-repository:commandnotfound解决办法:先执行:apt-get-yinstallsoftware-pro......
  • 在使用docker-compose build一个faq服务Helpy 时报错
    Helpy时报错如下:ERROR:failedtosolve:process"/bin/sh-cbundleinstall--withouttestdevelopment"didnotcompletesuccessfully:exitcode:11ERROR:Service'helpy'failedtobuild:Buildfailed有两种解释这种报错1、修改dockerfile ruby:2.5,然后......
  • 报错 org.springframework.dao.DataIntegrityViolationException: Error attempting t
       原因是持久化层的字段属性 跟数据库的没有对应上,类型不对dao.DataIntegrityViolationException:Errorattemptingtogetcolumn'STATUS'fromresultset.<iftest="record.status!=null">'STATUS'=#{record.status,jdbcType=......
  • influxdb报错:cache-max-memory-size exceeded
    转载请注明出处:influxdb报错日志: 该错误信息表示InfluxDB引擎超过了缓存最大内存大小。这意味着InfluxDB的缓存使用量超出了配置的限制。要解决此问题,可以采取以下步骤来定位和解决:检查配置文件:首先,请确保InfluxDB配置文件中没有设置错误。在配置文件......