Cannot perform a shrinkdatabase operation inside a user transaction. Terminate the transaction and reissue the statement.

Have you ever come across a Error saying "Cannot perform a shrinkdatabase operation inside a user transaction. Terminate the transaction and reissue the statement."

what happened, what is the case. Its simple, You might be running the ShrinkDatabase command within a transaction as sample below.

BEGIN TRAN
GO
DBCC SHRINKDATABASE(N'Test' )
GO

Error Screenshot:

Since shrinkdatabase is a Serialized operation and you cannot run under this a transaction. Just run the ShrinkDatabase command outside transaction.

Issue Rollback Statement to make sure the transaction is no longer valid. Then run the below command

USE master
GO
DBCC SHRINKDATABASE(N'Test' )
GO

Success Screenshot: