Print
Run this script in query analyzer against the master db
===================copy everything below this line=====================
USE master
GO
DECLARE @db_name varchar(500)
DECLARE dbn_cursor CURSOR FOR
SELECT [name] FROM sysdatabases;
OPEN dbn_cursor
FETCH NEXT FROM dbn_cursor
INTO @db_name
WHILE @@FETCH_STATUS = 0
BEGIN
select * from sysdatabases where name = @db_name
IF @@ERROR <> 0
BEGIN
declare @off int
print 'Restarting database '+@db_name
exec @off = sp_dboption @db_name, 'offline', 'TRUE'
IF @off <> 0
print 'Taking offline failed! Need manual workaround!'
else
begin
declare @on int
exec @on = sp_dboption @db_name, 'offline', 'FALSE' Â Â Â
IF @on <> 0
'Bringing online failed! Need manual workaround!'
else
print 'Restart successfull!'
end
END
FETCH NEXT FROM dbn_cursor
INTO @db_name
END
CLOSE dbn_cursor
DEALLOCATE dbn_cursor
GO
===================copy everything above=====================
Related Articles