zoukankan      html  css  js  c++  java
  • a Storage Procedure for waiting for a database come online


    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

  • 相关阅读:
    Apache工作原理
    Mysql主从复制
    Apache 工作模式
    Codeforces 932E Team Work
    【TJOI2018】教科书般的亵渎
    Codeforces 960G Bandit Blues
    斯特林数&斯特林反演
    【BZOJ4916】神犇与蒟蒻
    【BZOJ3944】Sum
    【BZOJ4805】欧拉函数求和
  • 原文地址:https://www.cnblogs.com/liunatural/p/1124959.html
Copyright © 2011-2022 走看看