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
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
相关文章推荐
- 初学android studio遇到的waiting for target device to come online
- android studio 运行项目时提示waiting for target device to come online,并且会卡死
- [Android](Problem)-"Waiting for target device to come online".
- 【Android】[Problem]-"Waiting for target device to come online".
- waiting for target device to come online
- Android studio下 Waiting for target device to come online
- Waiting for target device to come online
- android studio 无法启动AVD,运行程序一直显示waiting for device to come online
- 【Android】[Problem]-"Waiting for target device to come online".
- 解决Android Studio AVD "waiting for target device to come online"问题
- linux下使用Android studio启动模拟器时提示 waiting for target device to come online 的问题
- 关于Android studio 模拟器打不开,而且连不上第三方模拟器,一直停留在waiting for target deviceto come online
- Android studio卡在waiting for target device to come online
- NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: WebKitLocalStorageDatabasePathPreferenc
- 转载:Postgres-XC: Waiting for online data redistribution
- server 2 task(s) are sleeping waiting for space to become available in the log segment for database tempdb.
- installer sakila sample database for windows
- MySQL出现Waiting for table metadata lock的场景浅析
- How to disable Storage I/O Control for an unavailable datastore (VMware Front Experience)
- OCM_Session8_1_Preparing the Primary Database for Standby Database Creation