Skip to content

Commit 82de540

Browse files
[5.2.1] | Fix SqlConnection.FireInfoMessageEventOnUserErrors when set to true throws an exception (#2399) (#2505)
1 parent 2391025 commit 82de540

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6776,7 +6776,7 @@ internal SqlBatchCommand GetCurrentBatchCommand()
67766776
}
67776777
else
67786778
{
6779-
return _rpcArrayOf1[0].batchCommand;
6779+
return _rpcArrayOf1?[0].batchCommand;
67806780
}
67816781
}
67826782

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7487,7 +7487,7 @@ internal SqlBatchCommand GetCurrentBatchCommand()
74877487
}
74887488
else
74897489
{
7490-
return _rpcArrayOf1[0].batchCommand;
7490+
return _rpcArrayOf1?[0].batchCommand;
74917491
}
74927492
}
74937493

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,29 @@ public static void SqlPasswordConnectionTest()
474474
using SqlConnection sqlConnection = new(b.ConnectionString);
475475
sqlConnection.Open();
476476
}
477+
478+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
479+
public static void ConnectionFireInfoMessageEventOnUserErrorsShouldSucceed()
480+
{
481+
using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
482+
{
483+
string command = "print";
484+
string commandParam = "OK";
485+
486+
connection.FireInfoMessageEventOnUserErrors = true;
487+
488+
connection.InfoMessage += (sender, args) =>
489+
{
490+
Assert.Equal(commandParam, args.Message);
491+
};
492+
493+
connection.Open();
494+
495+
using SqlCommand cmd = connection.CreateCommand();
496+
cmd.CommandType = System.Data.CommandType.Text;
497+
cmd.CommandText = $"{command} '{commandParam}'";
498+
cmd.ExecuteNonQuery();
499+
}
500+
}
477501
}
478502
}

0 commit comments

Comments
 (0)