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

NullReferenceException with Microsoft.Data.SqlClient 5.2.0 and with event handler for Backup.PercentComplete #162

Open
geo-var opened this issue Apr 22, 2024 · 2 comments

Comments

@geo-var
Copy link

geo-var commented Apr 22, 2024

In our app we reference both NuGet-Packages Microsoft.SqlServer.SqlManagementObjects and Microsoft.Data.SqlClient.
We use SMO for many DB-related tasks, incl. Backup of the app databases.
We refresh the NuGet references regularly, actually we use Microsoft.SqlServer.SqlManagementObjects 171.30.0 and Microsoft.Data.SqlClient 5.1.5.
Everything worked fine until we updated Microsoft.Data.SqlClient to the actual version 5.2.0. Now our backup code throws NullReferenceException. As a workaround we switched back to Microsoft.Data.SqlClient 5.1.5.
We were able to reproduce the issue with the sample from https://learn.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/tasks/backing-up-and-restoring-databases-and-transaction-logs?view=sql-server-ver16#backing-up-databases-and-transaction-logs-in-visual-c
The only difference is the added event handler for Backup.PercentComplete. With it, the sample throws NullReferenceException when calling Backup.SqlBackup() and using SqlClient 5.2.0. The same code works fine with SqlClient 5.1.5 or earlier.

The sample is attached to the issue.
MS_SMO_BackupBug.zip

@JRahnama
Copy link

@geo-var
Based on below stack

System.NullReferenceException: Object reference not set to an instance of an object.
   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 async, Int32 timeout, Boolean asyncWrite)

this issue is addressed on SqlClient side by PR #2399. Hotfix release v5.2.1 is in our plan, date yet TBD.

@geo-var
Copy link
Author

geo-var commented Apr 23, 2024

Thanks a lot,
we will test the hotfix when released and will let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants