Here is my query:
IF EXISTS(%some query%)
BEGIN
BEGIN TRY
ALTER DATABASE [MyDatabase] SET single_user WITH ROLLBACK IMMEDIATE;
--do something
--throw some exception
END TRY
BEGIN CATCH
--here I want to set database back to multi_user
RAISERROR ('DBErrorMessage', @ErrorSeverity, @ErrorState);
END CATCH
END
What is the best way to set database back to multi_user
? I am afraid that the most straightforward way might lead to an
Database 'MyDatabase' is already open and can only have one user at a time.
exception.
By the most straightforward way I mean this one:
ALTER DATABASE [MyDatabase] SET MULTI_USER