您的位置:首页 > 大数据 > 人工智能

a Storage Procedure for waiting for a database come online

2008-03-27 12:25 351 查看
if exists(select * from sys.objects where name like 'sp_waitfordbonline' and type ='P')
drop procedure sp_waitfordbonline
go

create procedure sp_waitfordbonline @dbname varchar(30), @timeout int
as
begin
-- waitfor db to come online
declare @status int
declare @loop int
declare @time int

select @time=0
select @loop=1
if (@timeout<=0)
print 'The minimum wait time for db to come online is set to 10 seconds'
while(@loop!=0)
begin
select @status=databaseproperty(@dbname,'IsInRecovery')
if(@status=0)

--Yukon and latest version
--select @desc=state_desc from sys.databases where name =@dbname
--if(@desc='ONLINE')
begin
select @loop=0
dbcc checkdb(@dbname) with no_infomsgs
end
else
begin
select @time = @time+1
waitfor delay '00:00:10'
end
if (@time>@timeout*6)
begin
select @loop=0
print 'Database:' + @dbname + ' did not come online in ' + convert(varchar(10),@time*10) + ' seconds'
end
end
end
go
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐