Core component of SQL Server for storing, processing, and securing data
This is obviously a bug in SQL Server and an ugly one.
I tested your repro, and found that:
- On SQL 2019, the entire SQL Server process dies.
- On SQL 2022, only my own process dies, but SQL Server survives.
- On SQL 2025, the batch completes successfully.
But I am not sure that this means that the issue has been fixed. Do I understand you correctly that sometimes you can run this without errors, but if you restart SQL Server the error starts to appear?
The full error message reads:
Process ID 75 attempted to unlock a resource it does not own: DATABASE: 2:0 [PLANGUIDE]. Retry the transaction, because this error may be caused by a timing condition. If the problem persists, contact the database administrator.
So it could be that is pure luck that it completes without errors on my SQL 2025 instance.
I also find that if I add a go before the rollback statement, so that the ROLLBACK statement come in a separate batch, I don't seem to get the error.
The way to deal with bugs like this is to open a support case with Microsoft. However, since SQL 2019 is out of mainstream support, it is unlikely that Microsoft will fix this in SQL 2019.
I would assume that if this something you run into, you can easily work around the issue, so it is not really blocking you, am I right?