Skip to content
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 @@ -2915,8 +2915,15 @@ private Task<object> InternalExecuteScalarAsync(CancellationToken cancellationTo
}
catch (Exception e)
{
// exception thrown by Dispose...
source.SetException(e);
// exception thrown by Dispose or NextResultAsync cancellation...
if (e is OperationCanceledException && cancellationToken.IsCancellationRequested)
{
source.SetCanceled();
}
else
{
source.SetException(e);
}
}
},
TaskScheduler.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3130,8 +3130,15 @@ private Task<object> InternalExecuteScalarAsync(CancellationToken cancellationTo
}
catch (Exception e)
{
// exception thrown by Dispose...
source.SetException(e);
// exception thrown by Dispose or NextResultAsync cancellation...
if (e is OperationCanceledException && cancellationToken.IsCancellationRequested)
{
source.SetCanceled();
}
else
{
source.SetException(e);
}
}
},
TaskScheduler.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ public void ExecuteScalar()
{
using SqlConnection connection = new SqlConnection((new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString) { MultipleActiveResultSets = true }).ConnectionString);
using SqlCommand command = connection.CreateCommand();
ConcurrentQueue<string> messages = new ConcurrentQueue<string>();

connection.InfoMessage += (object sender, SqlInfoMessageEventArgs args) =>
messages.Enqueue(args.Message);

connection.Open();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public static void ExecuteScalar_ShouldThrowOnConversionError()
try
{
// Arrange
// Insert valid VARCHAR values - '42-43' is a valid string, not an invalid number
DataTestUtility.CreateTable(connection, tableName, "(Id INT IDENTITY(1,1) NOT NULL, Val VARCHAR(10) NOT NULL)");
// Insert valid VARCHAR values - '42-43' is a valid string but not a valid number
DataTestUtility.CreateTable(connection, tableName, "(Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, Val VARCHAR(10) NOT NULL)");
using (SqlCommand insertCmd = connection.CreateCommand())
{
insertCmd.CommandText =
Expand Down Expand Up @@ -68,9 +68,9 @@ public static void ExecuteScalar_TransactionShouldRollbackOnError()
try
{
// Arrange
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings
DataTestUtility.CreateTable(connection, sourceTable, "(Id INT IDENTITY(1,1) NOT NULL, Val VARCHAR(10) NOT NULL)");
DataTestUtility.CreateTable(connection, targetTable, "(Id INT IDENTITY(1,1) NOT NULL, Val1 INT NOT NULL, Val2 INT NOT NULL)");
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings but not valid numbers
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is inaccurate: '12345' is a valid number when converting VARCHAR to INT; only '42-43' fails conversion. Consider rewording to avoid implying both values are not valid numbers (e.g., clarify that one value converts and the other does not).

Suggested change
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings but not valid numbers
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings, but only '12345' converts to INT

Copilot uses AI. Check for mistakes.
DataTestUtility.CreateTable(connection, sourceTable, "(Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, Val VARCHAR(10) NOT NULL)");
DataTestUtility.CreateTable(connection, targetTable, "(Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, Val1 INT NOT NULL, Val2 INT NOT NULL)");
using (SqlCommand insertCmd = connection.CreateCommand())
{
insertCmd.CommandText =
Expand Down Expand Up @@ -165,7 +165,7 @@ public static async Task ExecuteScalarAsync_ShouldThrowOnConversionError()
try
{
// Arrange
DataTestUtility.CreateTable(connection, tableName, "(Id INT IDENTITY(1,1) NOT NULL, Val VARCHAR(10) NOT NULL)");
DataTestUtility.CreateTable(connection, tableName, "(Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, Val VARCHAR(10) NOT NULL)");
using (SqlCommand insertCmd = connection.CreateCommand())
{
insertCmd.CommandText =
Expand Down Expand Up @@ -203,9 +203,9 @@ public static async Task ExecuteScalarAsync_TransactionShouldRollbackOnError()
try
{
// Arrange
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings
DataTestUtility.CreateTable(connection, sourceTable, "(Id INT IDENTITY(1,1) NOT NULL, Val VARCHAR(10) NOT NULL)");
DataTestUtility.CreateTable(connection, targetTable, "(Id INT IDENTITY(1,1) NOT NULL, Val1 INT NOT NULL, Val2 INT NOT NULL)");
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings but not valid numbers
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is inaccurate: '12345' converts to INT successfully; the conversion error is caused by the '42-43' row. Rewording this will prevent confusion when interpreting why the WHERE clause throws.

Suggested change
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings but not valid numbers
// sourceTable.Val is VARCHAR - both '12345' and '42-43' are valid strings, but only '42-43' cannot be converted to INT

Copilot uses AI. Check for mistakes.
DataTestUtility.CreateTable(connection, sourceTable, "(Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, Val VARCHAR(10) NOT NULL)");
DataTestUtility.CreateTable(connection, targetTable, "(Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED, Val1 INT NOT NULL, Val2 INT NOT NULL)");
using (SqlCommand insertCmd = connection.CreateCommand())
{
insertCmd.CommandText =
Expand Down