Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Add Async flag to SqlClient NamedPipes' PipeStream to resolve an issu…
Browse files Browse the repository at this point in the history
…e with connection hangs while using MARS over NP. (#19022)
  • Loading branch information
corivera authored and Petermarcu committed Apr 27, 2017
1 parent 010b2e7 commit 9c668c8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public SNINpHandle(string serverName, string pipeName, long timerExpire, object

try
{
_pipeStream = new NamedPipeClientStream(serverName, pipeName, PipeDirection.InOut, PipeOptions.WriteThrough, Security.Principal.TokenImpersonationLevel.None);
_pipeStream = new NamedPipeClientStream(
serverName,
pipeName,
PipeDirection.InOut,
PipeOptions.Asynchronous | PipeOptions.WriteThrough);

bool isInfiniteTimeOut = long.MaxValue == timerExpire;
if (isInfiniteTimeOut)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,25 @@ public static class LocalDBTest
[ConditionalFact(nameof(IsLocalDBEnvironmentSet))]
public static void LocalDBConnectionTest()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder("server=(localdb)\\MSSQLLocalDB");
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(@"server=(localdb)\MSSQLLocalDB");
builder.IntegratedSecurity = true;
builder.ConnectTimeout = 2;
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
OpenConnection(builder.ConnectionString);
}

[ConditionalFact(nameof(IsLocalDBEnvironmentSet))]
public static void LocalDBMarsTest()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(@"server=(localdb)\MSSQLLocalDB;");
builder.IntegratedSecurity = true;
builder.MultipleActiveResultSets = true;
builder.ConnectTimeout = 2;
OpenConnection(builder.ConnectionString);
}

private static void OpenConnection(string connString)
{
using (SqlConnection connection = new SqlConnection(connString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("SELECT @@SERVERNAME", connection))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ public static class MARSTest
{
private static readonly string _connStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { MultipleActiveResultSets = true }).ConnectionString;

[CheckConnStrSetupFact]
public static void NamedPipesMARSTest()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.NpConnStr);
builder.MultipleActiveResultSets = true;
builder.ConnectTimeout = 5;

using (SqlConnection conn = new SqlConnection(builder.ConnectionString))
{
conn.Open();
using (SqlCommand command = new SqlCommand("SELECT @@SERVERNAME", conn))
{
var result = command.ExecuteScalar();
Assert.NotNull(result);
}
}
}

#if DEBUG
[CheckConnStrSetupFact]
public static void MARSAsyncTimeoutTest()
Expand Down

0 comments on commit 9c668c8

Please sign in to comment.