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

System.NullReferenceException: 'Object reference not set to an instance of an object.' on FireInfoMessageEventOnUserErrors = true #2502

Closed
h17117 opened this issue May 16, 2024 · 3 comments
Labels
🆕 Triage Needed For new issues, not triaged yet. 2️⃣ Duplicate Issue/PR that is a duplicate and already exists.

Comments

@h17117
Copy link

h17117 commented May 16, 2024

Describe the bug

Info message event is broken by version upgrade from 5.1.5 to 5.2.0

Exception message: System.NullReferenceException: 'Object reference not set to an instance of an object.'

Stack trace:
   at Microsoft.Data.SqlClient.SqlCommand.GetCurrentBatchCommand()
   at Microsoft.Data.SqlClient.TdsParser.FireInfoMessageEvent(SqlConnection connection, SqlCommand command, TdsParserStateObject stateObj, SqlError error)
   at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
   at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\Master\source\repos\Example1\ConsoleApp1\Program.cs:line 19

To reproduce

Complete code:

using Microsoft.Data.SqlClient;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection sqlConnection = new SqlConnection("integrated security=true; encrypt=false"))
            {
                sqlConnection.InfoMessage += (s, e) =>
                {
                    Console.WriteLine(e.Message);
                };
                sqlConnection.FireInfoMessageEventOnUserErrors = true;
                sqlConnection.Open();
                using (SqlCommand c = new SqlCommand("backup database master", sqlConnection))
                {
                    c.ExecuteNonQuery();
                }
            }
        }
    }
}

Expected behavior

Info message to be fired instead of Exception.

Further technical details

Microsoft.Data.SqlClient version: (5.2.0)
.NET target: (Core 8, 4.6.2, 4.8)
SQL Server version:
Operating system: Windows

@ErikEJ
Copy link
Contributor

ErikEJ commented May 16, 2024

Duplicate of #2388

@arellegue arellegue added the 2️⃣ Duplicate Issue/PR that is a duplicate and already exists. label May 16, 2024
@arellegue
Copy link
Contributor

arellegue commented May 16, 2024

@h17117 This issue was fixed on PR #2399. This fix will be included in Hotfix 5.2.1 which released date is yet to be determined.

@arellegue arellegue added the 🆕 Triage Needed For new issues, not triaged yet. label May 16, 2024
@JRahnama
Copy link
Contributor

Closing as duplicate of #2388. Issue is addressed on PR #2399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 Triage Needed For new issues, not triaged yet. 2️⃣ Duplicate Issue/PR that is a duplicate and already exists.
Projects
Development

No branches or pull requests

4 participants