Today, we worked on a new service request where our customer tried to modify a parameter of a new database, just a couple minutes after that they have created it.
During aprox. 5-10 minutes they were not able to modify this parameter after the database was created and our customer asked why.
Every time that they tried to change the value of this parameter they got the following error message:
Why?
How we found it:
If you want to automate this process using a script, for example, to change the containment parameter:
CREATE OR ALTER PROCEDURE ChangeStatus
AS
BEGIN
BEGIN TRY
ALTER DATABASE <databasename> set containment =partial
END TRY
BEGIN CATCH
PRINT @@ERROR
END CATCH
END
DECLARE @VALUE AS INT = -1
DECLARE @nTimes as INT = 0
WHILE(@nTimes <=10)
BEGIN
SELECT @Value = (SELECT Containment FROM sys.databases WHERE name='databasename')
IF @VALUE <> 0 BREAK;
SET @nTimes = @ntimes +1
IF @Value = 0
BEGIN
PRINT 'Doing #'
EXEC ChangeStatus
WAITFOR DELAY '00:02:00'
END
END
Enjoy!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.