diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index 39dbb917e0..d01c686d04 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -6776,7 +6776,7 @@ internal SqlBatchCommand GetCurrentBatchCommand() } else { - return _rpcArrayOf1[0].batchCommand; + return _rpcArrayOf1?[0].batchCommand; } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs index 0ac6ed775e..94cd927c1d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -7487,7 +7487,7 @@ internal SqlBatchCommand GetCurrentBatchCommand() } else { - return _rpcArrayOf1[0].batchCommand; + return _rpcArrayOf1?[0].batchCommand; } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs index 60260fe79f..bf26f84018 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs @@ -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(); + } + } } }