diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbMetaDataFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbMetaDataFactory.cs index 12b572bb47..5ca28b5458 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbMetaDataFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbMetaDataFactory.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.Data.Common; +using Microsoft.Data.SqlClient; using System; using System.Data; using System.Data.Common; @@ -126,8 +127,11 @@ private DataTable ExecuteCommand(DataRow requestedCollectionRow, string[] restri } DbCommand command = connection.CreateCommand(); + SqlConnection castConnection = connection as SqlConnection; + command.CommandText = sqlCommand; command.CommandTimeout = Math.Max(command.CommandTimeout, 180); + command.Transaction = castConnection?.GetOpenTdsConnection()?.CurrentTransaction?.Parent; for (int i = 0; i < numberOfRestrictions; i++) { diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlSchemaInfoTest/SqlSchemaInfoTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlSchemaInfoTest/SqlSchemaInfoTest.cs index 36e354f8b2..83c92b7236 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlSchemaInfoTest/SqlSchemaInfoTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlSchemaInfoTest/SqlSchemaInfoTest.cs @@ -15,13 +15,27 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests public static class SqlSchemaInfoTest { #region TestMethods - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] - public static void TestGetSchema() + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] + [InlineData(true)] + [InlineData(false)] + public static void TestGetSchema(bool openTransaction) { using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString)) { conn.Open(); - DataTable dataBases = conn.GetSchema("DATABASES"); + DataTable dataBases; + + if (openTransaction) + { + using (SqlTransaction transaction = conn.BeginTransaction()) + { + dataBases = conn.GetSchema("DATABASES"); + } + } + else + { + dataBases = conn.GetSchema("DATABASES"); + } Assert.True(dataBases.Rows.Count > 0, "At least one database is expected");