Skip to content

New pool scaffolding #3352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 22, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -73,6 +74,13 @@ public static void BasicConnectionPoolingTest(string connectionString)
}
}

private enum Tristate : byte
{
NotInitialized = 0,
False = 1,
True = 2
}

/// <summary>
/// Tests that when UseConnectionPoolV2 context switch is enabled, opening a connection throws NotImplementedException
/// </summary>
Expand All @@ -82,8 +90,9 @@ public static void UseConnectionPoolV2ThrowsNotImplemented(string connectionStri
{
try
{
// Enable the UseConnectionPoolV2 context switch
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseConnectionPoolV2", true);
Type switchesType = typeof(SqlCommand).Assembly.GetType("Microsoft.Data.SqlClient.LocalAppContextSwitches");
FieldInfo switchField = switchesType.GetField("s_useConnectionPoolV2", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
switchField.SetValue(null, Tristate.True);

using (SqlConnection connection = new SqlConnection(connectionString))
{
Expand All @@ -94,7 +103,9 @@ public static void UseConnectionPoolV2ThrowsNotImplemented(string connectionStri
finally
{
// Reset the context switch
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseConnectionPoolV2", false);
Type switchesType = typeof(SqlCommand).Assembly.GetType("Microsoft.Data.SqlClient.LocalAppContextSwitches");
FieldInfo switchField = switchesType.GetField("s_useConnectionPoolV2", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
switchField.SetValue(null, Tristate.False);
}
}

Expand Down
Loading