You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NullReferenceException with Microsoft.Data.SqlClient 5.2.0 and with event handler for Backup.PercentComplete #162
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.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Data.SqlClient.SqlCommand.GetCurrentBatchCommand()
at Microsoft.Data.SqlClient.TdsParser.FireInfoMessageEvent(SqlConnectionconnection,SqlCommandcommand,TdsParserStateObjectstateObj,SqlErrorerror)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehaviorrunBehavior,SqlCommandcmdHandler,SqlDataReaderdataStream,BulkCopySimpleResultSetbulkCopyHandler,TdsParserStateObjectstateObj,Boolean&dataReady)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(StringmethodName,Booleanasync,Int32timeout,BooleanasyncWrite)
this issue is addressed on SqlClient side by PR #2399. Hotfix release v5.2.1 is in our plan, date yet TBD.
Activity
JRahnama commentedon Apr 22, 2024
geo-var
Based on below stack
this issue is addressed on SqlClient side by PR #2399. Hotfix release v5.2.1 is in our plan, date yet TBD.
geo-var commentedon Apr 23, 2024
Thanks a lot,
we will test the hotfix when released and will let you know.