From 2785ba331b7468e50830263cc73621f8f68a9ff0 Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Mon, 4 Mar 2024 16:26:01 +0000 Subject: [PATCH] Log warn when the Microsoft.Data.SqlClient version is below 5.2.0 (#1305) * Log warn when the client version is below 5.2.0 to make sure clients start upgrading to later versions without enforcing them to have Encrypt=true that was introduced in a breaking change in 4.x of the client * Update src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs * Update src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs --- .../SqlServerTransportInfrastructure.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs b/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs index 1dd8befbe..c00e7ce97 100644 --- a/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs +++ b/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs @@ -3,9 +3,15 @@ namespace NServiceBus.Transport.SqlServer using System; using System.Collections.Generic; using System.Linq; + using System.Reflection; using System.Threading; using System.Threading.Tasks; using System.Transactions; +#if SYSTEMDATASQLCLIENT + using System.Data.SqlClient; +#else + using Microsoft.Data.SqlClient; +#endif using Logging; using NServiceBus.Transport.SqlServer.PubSub; using Transport; @@ -21,6 +27,18 @@ internal SqlServerTransportInfrastructure(SqlServerTransport transport, HostSett tableBasedQueueCache = new TableBasedQueueCache(addressTranslator, !isEncrypted); connectionFactory = CreateConnectionFactory(); + + if (typeof(SqlConnection).Namespace != "Microsoft.Data.SqlClient") + { + return; + } + + var informationalVersion = typeof(SqlConnection).Assembly.GetCustomAttributes().OfType().Single(); + var currentClientVersion = new Version(informationalVersion.InformationalVersion.Split('+').First()); + if (currentClientVersion < new Version(5, 2, 0)) + { + _logger.WarnFormat("You are using an outdated version '{0}' of Microsoft.Data.SqlClient. We recommend using version 5.2.0 or later by adding a top-level package reference to avoid known problems in older versions of the client. Consult the SQL client release notes https://github.com/dotnet/SqlClient/blob/main/release-notes for breaking changes before upgrading.", currentClientVersion); + } } public async Task ConfigureSubscriptions(string catalog, CancellationToken cancellationToken = default)