@@ -24,7 +24,7 @@ public class MySQLConnection : EasyClient<MySQLPacket>
2424 public bool IsAuthenticated { get ; private set ; }
2525
2626 public MySQLConnection ( string host , int port , string userName , string password )
27- : base ( new MySQLPacketFilter ( MySQLPacketDecoder . Singleton ) )
27+ : base ( new MySQLPacketFilter ( MySQLPacketDecoder . ClientInstance ) )
2828 {
2929 _host = host ?? throw new ArgumentNullException ( nameof ( host ) ) ;
3030 _port = port > 0 ? port : DefaultPort ;
@@ -40,9 +40,12 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
4040 if ( _port <= 0 )
4141 throw new ArgumentOutOfRangeException ( nameof ( _port ) , "Port must be a positive integer." ) ;
4242
43- var endPoint = new DnsEndPoint ( _host , _port ) ;
43+ var endPoint = new DnsEndPoint ( _host , _port , AddressFamily . InterNetwork ) ;
4444
45- await ConnectAsync ( endPoint , cancellationToken ) . ConfigureAwait ( false ) ;
45+ var connected = await ConnectAsync ( endPoint , cancellationToken ) . ConfigureAwait ( false ) ;
46+
47+ if ( ! connected )
48+ throw new InvalidOperationException ( $ "Failed to connect to MySQL server at { _host } :{ _port } ") ;
4649
4750 // Wait for server's handshake packet
4851 var packet = await ReceiveAsync ( ) . ConfigureAwait ( false ) ;
@@ -52,7 +55,7 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
5255 // Prepare handshake response
5356 var handshakeResponse = new HandshakeResponsePacket
5457 {
55- CapabilityFlags = ( uint ) ( ClientCapabilities . CLIENT_PROTOCOL_41 |
58+ CapabilityFlags = ( uint ) ( ClientCapabilities . CLIENT_PROTOCOL_41 |
5659 ClientCapabilities . CLIENT_SECURE_CONNECTION |
5760 ClientCapabilities . CLIENT_PLUGIN_AUTH |
5861 ClientCapabilities . CLIENT_CONNECT_WITH_DB ) ,
@@ -71,7 +74,7 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
7174
7275 // Wait for authentication result (OK packet or Error packet)
7376 var authResult = await ReceiveAsync ( ) . ConfigureAwait ( false ) ;
74-
77+
7578 switch ( authResult )
7679 {
7780 case OKPacket okPacket :
@@ -80,8 +83,8 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
8083 break ;
8184 case ErrorPacket errorPacket :
8285 // Authentication failed
83- var errorMsg = ! string . IsNullOrEmpty ( errorPacket . ErrorMessage )
84- ? errorPacket . ErrorMessage
86+ var errorMsg = ! string . IsNullOrEmpty ( errorPacket . ErrorMessage )
87+ ? errorPacket . ErrorMessage
8588 : "Authentication failed" ;
8689 throw new InvalidOperationException ( $ "MySQL authentication failed: { errorMsg } (Error { errorPacket . ErrorCode } )") ;
8790 default :
@@ -166,5 +169,9 @@ public async Task DisconnectAsync()
166169 IsAuthenticated = false ;
167170 }
168171 }
172+
173+ protected override void OnError ( string message , Exception exception )
174+ {
175+ }
169176 }
170177}
0 commit comments