@@ -485,10 +485,9 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
485
485
SupportsQueryAttributes = ( ServerCapabilities & ProtocolCapabilities . QueryAttributes ) != 0 ;
486
486
m_supportsSessionTrack = ( ServerCapabilities & ProtocolCapabilities . SessionTrack ) != 0 ;
487
487
var serverSupportsSsl = ( ServerCapabilities & ProtocolCapabilities . Ssl ) != 0 ;
488
- m_characterSet = S2ServerVersion . Version >= S2Versions . SupportsUtf8Mb4 ? CharacterSet . Utf8Mb4GeneralCaseInsensitive : CharacterSet . Utf8GeneralCaseInsensitive ;
489
- m_setNamesPayload = S2ServerVersion . Version >= S2Versions . SupportsUtf8Mb4 ?
490
- ( SupportsQueryAttributes ? s_setNamesUtf8mb4WithAttributesPayload : s_setNamesUtf8mb4NoAttributesPayload ) :
491
- ( SupportsQueryAttributes ? s_setNamesUtf8WithAttributesPayload : s_setNamesUtf8NoAttributesPayload ) ;
488
+ // Default to plain UTF‑8 until we’ve probed the server’s real version
489
+ m_characterSet = CharacterSet . Utf8GeneralCaseInsensitive ;
490
+ m_setNamesPayload = SupportsQueryAttributes ? s_setNamesUtf8WithAttributesPayload : s_setNamesUtf8NoAttributesPayload ;
492
491
493
492
// disable pipelining for SingleStore
494
493
m_supportsPipelining = false ;
@@ -549,10 +548,25 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
549
548
if ( m_useCompression )
550
549
m_payloadHandler = new CompressedPayloadHandler ( m_payloadHandler . ByteHandler ) ;
551
550
552
- // set 'collation_connection' to the server default
553
- await SendAsync ( m_setNamesPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
554
- payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
555
- OkPayload . Verify ( payload . Span , SupportsDeprecateEof , SupportsSessionTrack ) ;
551
+ // set 'collation_connection' to the server default (probing utf8mb4 support)
552
+ try
553
+ {
554
+ var utf8Mb4Payload = SupportsQueryAttributes
555
+ ? s_setNamesUtf8mb4WithAttributesPayload
556
+ : s_setNamesUtf8mb4NoAttributesPayload ;
557
+ await SendAsync ( utf8Mb4Payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
558
+ payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
559
+ OkPayload . Verify ( payload . Span , SupportsDeprecateEof , SupportsSessionTrack ) ;
560
+
561
+ m_characterSet = CharacterSet . Utf8Mb4GeneralCaseInsensitive ;
562
+ m_setNamesPayload = utf8Mb4Payload ;
563
+ }
564
+ catch ( SingleStoreException )
565
+ {
566
+ await SendAsync ( m_setNamesPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
567
+ var reply = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
568
+ OkPayload . Verify ( reply . Span , SupportsDeprecateEof , SupportsSessionTrack ) ;
569
+ }
556
570
557
571
await GetRealServerDetailsAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
558
572
0 commit comments