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

SqlException.CreateException throws NullReferenceException when no batch #2387

Closed
kamilkulczyk opened this issue Mar 5, 2024 · 4 comments
Closed

Comments

@kamilkulczyk
Copy link

kamilkulczyk commented Mar 5, 2024

SqlException.CreateException calls for command?.GetCurrentBatchCommand()) even if there's no batch

While switching from (1) System.Data.SqlClient to (2) Microsoft.Data.SqlClient I got an error caused by this change of code:

  1. SqlException exc = SqlException.CreateException(sqlErs, serverVersion, _connHandler);
  2. SqlException exc = SqlException.CreateException(sqlErs, serverVersion, _connHandler, innerException:null, batchCommand: command?.GetCurrentBatchCommand();

An error occurs when ExecuteNonQuery() a script that has a "caution" message and FireInfoMessageEventOnUserErrors = true. My Script uses SP_RENAME and has "Caution: Changing any part of an object name could break scripts and stored procedures." message.

SqlException.CreateException() => command?.GetCurrentBatchCommand() =>return _rpcArrayOf1[0].batchCommand, where _rpcArrayOf1 is null, cause never initialized. That throws NullReferenceException.

To reproduce

  1. C# .NET 8 with Microsoft.Data.SqlClient
  2. Simple script with SP_RENAME
  3. FireInfoMessageEventOnUserErrors = true
  4. ExecuteNonQuery()

Expected behavior

I'd like to be able to execute a script with FireInfoMessageEventOnUserErrors = true, even if it's not a batch.

Is that an error or do I miss something?

@fr4gles
Copy link

fr4gles commented Mar 5, 2024

Same issue reported here #2388

@JRahnama
Copy link
Member

JRahnama commented Mar 6, 2024

@kamilkulczyk Thank you for reaching out. We will update you on the investigation results.

@kamilkulczyk
Copy link
Author

@JRahnama I assume that if #2388 is closed this is as well?

@JRahnama
Copy link
Member

JRahnama commented Apr 3, 2024

@kamilkulczyk thanks for reminding me.

Closing as this is addressed in PR #2399

@JRahnama JRahnama closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

3 participants