Skip to content
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

Fix | Fix issue with SqlCommand OnStatementCompleted event not being triggered #216

Merged
merged 5 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
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 @@ -2792,6 +2792,11 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio
cmd.InternalRecordsAffected = count;
}
}
// Skip the bogus DONE counts sent by the server
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
if (stateObj._receivedColMetaData || (curCmd != TdsEnums.SELECT))
{
cmd.OnStatementCompleted(count);
}
}

stateObj._receivedColMetaData = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@
<Compile Include="DDBasics\DDMARSTest\DDMARSTest.cs" />
<Compile Include="ProviderAgnostic\MultipleResultsTest\MultipleResultsTest.cs" />
<Compile Include="ProviderAgnostic\ReaderTest\ReaderTest.cs" />
<Compile Include="SQL\AsyncTest\AsyncTest.cs" />
<Compile Include="SQL\CommandCancelTest\CommandCancelTest.cs" />
<Compile Include="SQL\AsyncTest\AsyncTest.cs" />
<Compile Include="SQL\SqlCommand\SqlCommandCompletedTest.cs" />
<Compile Include="SQL\SqlCommand\SqlCommandCancelTest.cs" />
<Compile Include="SQL\ConnectionPoolTest\ConnectionPoolTest.cs" />
<Compile Include="SQL\ConnectivityTests\ConnectivityTest.cs" />
<Compile Include="SQL\DataBaseSchemaTest\ConnectionSchemaTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
public static class CommandCancelTest
public static class SqlCommandCancelTest
{
// Shrink the packet size - this should make timeouts more likely
private static readonly string s_connStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { PacketSize = 512 }).ConnectionString;
Expand Down Expand Up @@ -139,7 +139,7 @@ private static void MultiThreadedCancel(string constr, bool async)

Task.WaitAll(tasks, 15 * 1000);

CommandCancelTest.VerifyConnection(command);
SqlCommandCancelTest.VerifyConnection(command);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Data;
using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
public static class SqlCommandCompletedTest
{
private static readonly string s_connStr = (new SqlConnectionStringBuilder(DataTestUtility.TcpConnStr) { PacketSize = 512 }).ConnectionString;
private static bool completedHandlerExecuted = false;

[CheckConnStrSetupFact]
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
public static void VerifyStatmentCompletedCalled()
{
using (var conn = new SqlConnection(s_connStr))
{
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) FROM sys.databases";
cmd.StatementCompleted += StatementCompletedHandler;
conn.Open();
var res = cmd.ExecuteScalar();
}
}
Assert.True(completedHandlerExecuted);
}

private static void StatementCompletedHandler(object sender, StatementCompletedEventArgs args)
{
completedHandlerExecuted = true;
}
}
}