From 160b5483d638b5912b5d97edee5bd39df5a7a979 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Fri, 1 Mar 2024 18:10:57 +0100 Subject: [PATCH 1/3] 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 --- .../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..1df085f42 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 taking an explicit package dependency to avoid issues with memory leaks or transactions running on .NET in the driver.", currentClientVersion); + } } public async Task ConfigureSubscriptions(string catalog, CancellationToken cancellationToken = default) From a2dc8581804a6c6cccc5a16ef0041d50decb2bd9 Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Fri, 1 Mar 2024 21:21:03 +0100 Subject: [PATCH 2/3] Update src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs --- .../SqlServerTransportInfrastructure.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs b/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs index 1df085f42..743f01fd6 100644 --- a/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs +++ b/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs @@ -37,7 +37,7 @@ internal SqlServerTransportInfrastructure(SqlServerTransport transport, HostSett 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 taking an explicit package dependency to avoid issues with memory leaks or transactions running on .NET in the driver.", currentClientVersion); + _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. See https://github.com/dotnet/SqlClient/blob/main/release-notes/5.0/5.0.0.md#breaking-changes for details on breaking changes before ugprading.", currentClientVersion); } } From d0a7e51edae4f276751c17d4057bf0cb2512ed42 Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Mon, 4 Mar 2024 10:25:08 +0100 Subject: [PATCH 3/3] Update src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs --- .../SqlServerTransportInfrastructure.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs b/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs index 743f01fd6..c00e7ce97 100644 --- a/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs +++ b/src/NServiceBus.Transport.SqlServer/SqlServerTransportInfrastructure.cs @@ -37,7 +37,7 @@ internal SqlServerTransportInfrastructure(SqlServerTransport transport, HostSett 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. See https://github.com/dotnet/SqlClient/blob/main/release-notes/5.0/5.0.0.md#breaking-changes for details on breaking changes before ugprading.", currentClientVersion); + _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); } }