Skip to content

Commit

Permalink
Enrol GetSchema commands into current transaction (#2876)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardneal authored Oct 9, 2024
1 parent 2a015d2 commit 40206cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 40206cd

Please sign in to comment.