Skip to content

Commit

Permalink
[5.2.1] | Fix SqlConnection.FireInfoMessageEventOnUserErrors when set…
Browse files Browse the repository at this point in the history
… to true throws an exception (dotnet#2399)
  • Loading branch information
DavoudEshtehari committed May 16, 2024
1 parent 82be9a6 commit c2bca36
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6776,7 +6776,7 @@ internal SqlBatchCommand GetCurrentBatchCommand()
}
else
{
return _rpcArrayOf1[0].batchCommand;
return _rpcArrayOf1?[0].batchCommand;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7487,7 +7487,7 @@ internal SqlBatchCommand GetCurrentBatchCommand()
}
else
{
return _rpcArrayOf1[0].batchCommand;
return _rpcArrayOf1?[0].batchCommand;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,5 +474,29 @@ public static void SqlPasswordConnectionTest()
using SqlConnection sqlConnection = new(b.ConnectionString);
sqlConnection.Open();
}

[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public static void ConnectionFireInfoMessageEventOnUserErrorsShouldSucceed()
{
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
string command = "print";
string commandParam = "OK";

connection.FireInfoMessageEventOnUserErrors = true;

connection.InfoMessage += (sender, args) =>
{
Assert.Equal(commandParam, args.Message);
};

connection.Open();

using SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = $"{command} '{commandParam}'";
cmd.ExecuteNonQuery();
}
}
}
}

0 comments on commit c2bca36

Please sign in to comment.