MySql 连接导致异常:System.IO.IOException 无法确定帧大小或接收到损坏的帧
MySql connection causes exception: System.IO.IOException Cannot determine the frame size or a corrupted frame was received
我正在从我的 C# 程序 (.NET 5.0) 连接到 MySql 数据库,但是每当我打开连接时,我都会收到以下异常(原始有更长的回溯):
System.IO.IOException: Cannot determine the frame size or a corrupted frame was received.
at System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Security.SslStream.ProcessAuthentication(Boolean isAsync, Boolean isApm, CancellationToken cancellationToken)
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at MySqlConnector.Core.ServerSession.InitSslAsync(ProtocolCapabilities serverCapabilities, ConnectionSettings cs, SslProtocols sslProtocols, IOBehavior ioBehavior, CancellationToken cancellationToken)
at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 470
抛出异常后,程序正常运行并成功连接到MySql。
我使用 MySql 连接器,使用 MySql.Data.MySqlClient 出现同样的问题。代码看起来像这样:
using MySqlConnector;
...
string _myConnectionString = "Server=myserver;User=myUser;Database=myDatabase;Password=myPassword";
using MySqlConnection conn = new(_myConnectionString);
conn.Open(); // The exception is thrown here
...
我没有在网上找到任何东西,关于如何使异常消失的任何想法?
这可能是由于协商 TLS 1.3 失败所致。尝试在连接字符串中设置 TLS Version
:
Server=myserver; TLS Version=TLS 1.2; User=myUser; ...
我正在从我的 C# 程序 (.NET 5.0) 连接到 MySql 数据库,但是每当我打开连接时,我都会收到以下异常(原始有更长的回溯):
System.IO.IOException: Cannot determine the frame size or a corrupted frame was received.
at System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Security.SslStream.ProcessAuthentication(Boolean isAsync, Boolean isApm, CancellationToken cancellationToken)
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at MySqlConnector.Core.ServerSession.InitSslAsync(ProtocolCapabilities serverCapabilities, ConnectionSettings cs, SslProtocols sslProtocols, IOBehavior ioBehavior, CancellationToken cancellationToken)
at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 470
抛出异常后,程序正常运行并成功连接到MySql。
我使用 MySql 连接器,使用 MySql.Data.MySqlClient 出现同样的问题。代码看起来像这样:
using MySqlConnector;
...
string _myConnectionString = "Server=myserver;User=myUser;Database=myDatabase;Password=myPassword";
using MySqlConnection conn = new(_myConnectionString);
conn.Open(); // The exception is thrown here
...
我没有在网上找到任何东西,关于如何使异常消失的任何想法?
这可能是由于协商 TLS 1.3 失败所致。尝试在连接字符串中设置 TLS Version
:
Server=myserver; TLS Version=TLS 1.2; User=myUser; ...