From aaed11035a00b81c2d2f5c36391df646fc57f9bf Mon Sep 17 00:00:00 2001 From: arontsang Date: Wed, 20 Sep 2023 05:37:09 +0000 Subject: [PATCH] Initialize transaction on CreateDbCommand() --- .../src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs | 5 +++++ .../src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs index a34be614cd..473d9cf629 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs @@ -159,6 +159,11 @@ override protected DbCommand CreateDbCommand() DbProviderFactory providerFactory = ConnectionFactory.ProviderFactory; command = providerFactory.CreateCommand(); command.Connection = this; + if (InnerConnection is SqlInternalConnection { CurrentTransaction: { Parent: {} transaction} }) + { + command.Transaction = transaction; + } + return command; } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs index 07d44f020c..5b8a0eafa0 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs @@ -205,6 +205,11 @@ override protected DbCommand CreateDbCommand() DbProviderFactory providerFactory = ConnectionFactory.ProviderFactory; DbCommand command = providerFactory.CreateCommand(); command.Connection = this; + if (InnerConnection is SqlInternalConnection { CurrentTransaction: { Parent: {} transaction} }) + { + command.Transaction = transaction; + } + return command; } }