Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Net.Security;
Expand Down Expand Up @@ -141,6 +142,9 @@ public override void Dispose()
_pipeStream.Dispose();
_pipeStream = null;
}

//Release any references held by _stream.
_stream = null;
}
}

Expand All @@ -157,7 +161,8 @@ public override uint Receive(out SNIPacket packet, int timeout)

if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);
var e = new Win32Exception();
return ReportErrorAndReleasePacket(packet, (uint)e.NativeErrorCode, 0, e.Message);
}
}
catch (ObjectDisposedException ode)
Expand Down
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 System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
Expand Down Expand Up @@ -440,7 +441,8 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds)

if (packet.Length == 0)
{
return ReportErrorAndReleasePacket(packet, 0, SNICommon.ConnTerminatedError, string.Empty);
var e = new Win32Exception();
return ReportErrorAndReleasePacket(packet, (uint)e.NativeErrorCode, 0, e.Message);
}

return TdsEnums.SNI_SUCCESS;
Expand Down
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 System.IO;
using System.IO.Pipes;

namespace System.Data.SqlClient.SNI
{
Expand Down Expand Up @@ -160,7 +161,12 @@ public override void SetLength(long value)
/// </summary>
public override void Flush()
{
_stream.Flush();
// Can sometimes get Pipe broken errors from flushing a PipeStream.
// PipeStream.Flush() also doesn't do anything, anyway.
if (!(_stream is PipeStream))
{
_stream.Flush();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ public static void LocalDBMarsTest()
OpenConnection(builder.ConnectionString);
}

[ConditionalFact(nameof(IsLocalDBEnvironmentSet))]
public static void InvalidDBTest()
{
using (var connection = new SqlConnection(@"Data Source=(localdb)\MSSQLLOCALDB;Database=DOES_NOT_EXIST;Pooling=false;"))
{
DataTestUtility.AssertThrowsWrapper<SqlException>(() => connection.Open());
}
}

private static void OpenConnection(string connString)
{
using (SqlConnection connection = new SqlConnection(connString))
Expand Down