sql 执行完语句后自动关机(在线等)!    我有一条语句,执行需要很长时间,能不能加条语句让它执行完后自动关机。               谢谢!

解决方案 »

  1.   

    觉得用CMD_SHELL 应该可以做到
      

  2.   

    . 使用 Windows NT net 命令
    下例显示 xp_cmdshell 在存储过程中的使用。下例先用 net send 通知用户 SQL Server 即将关闭,然后用 net pause 暂停服务器,最后用 net stop 关闭服务器。CREATE PROC shutdown10
    AS
    EXEC xp_cmdshell 'net send /domain:SQL_USERS ''SQL Server shutting down 
       in 10 minutes. No more connections allowed.', no_output
    EXEC xp_cmdshell 'net pause sqlserver'
    WAITFOR DELAY '00:05:00'
    EXEC xp_cmdshell 'net send /domain: SQL_USERS ''SQL Server shutting down 
       in 5 minutes.', no_output
    WAITFOR DELAY '00:04:00'
    EXEC xp_cmdshell 'net send /domain:SQL_USERS ''SQL Server shutting down 
       in 1 minute. Log off now.', no_output
    WAITFOR DELAY '00:01:00'
    EXEC xp_cmdshell 'net stop sqlserver', no_output原来真的有这个东西
      

  3.   

    做不到吗?我也是不懂,不知我那条语句要执行到啥时候,所以想问问,sql 做不到的话,别的什么也可以,就是让它执行完这条语句,然后电脑关机。
      

  4.   

    begin tran
       ....
       
       if @@error=0
       exec xp_cmdshell 'shutdown -m \\计算机名 -s -t 0'
    commit
    TRY
      

  5.   

    Shutdown.exe -s -t 3600 然后再加上这个定时关机的命令
      

  6.   

    exec xp_cmdshell 'shutdown -s '
      

  7.   

    dbcc dbreindex (fhdzk, '')就是这条语句,需要多长时间?
      

  8.   

    exec xp_cmdshell 'shutdown -s -t 0'这句绝对管用,刚试的,立即生效,一些资料都来不及保存.
      

  9.   

    sp_configure 'show advanced options',1
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    reconfigure
    goif @@error=0
    exec xp_cmdshell 'shutdown -m \\mm -s -t 100000'
    commit
      

  10.   


    (所影响的行数为 20 行)服务器: 消息 2812,级别 16,状态 62,行 3
    未能找到存储过程 'xp_cmdshell'。
      

  11.   


    先执行:
    sp_configure 'show advanced options',1
    go
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    go
    reconfigure
    go
    sp_configure 'show advanced options',0
    go
    reconfigure
    go
    再试试
      

  12.   

    已将配置选项 'show advanced options' 从 0 改为 1。请运行 RECONFIGURE 语句以安装。
    服务器: 消息 15123,级别 16,状态 1,过程 sp_configure,行 79
    配置选项 'xp_cmdshell' 不存在,也可能是高级选项。
     
    有效的配置选项为:已将配置选项 'show advanced options' 从 1 改为 0。请运行 RECONFIGURE 语句以安装。
      

  13.   

    xp_cmdshell是数据库的命令,跟XP系统没关系.
      

  14.   

    use master
    go
    sp_configure 'show advanced options',1
    go
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    go
    reconfigure
    go
    sp_configure 'show advanced options',0
    go
    reconfigure
    go重新执行一下,再执行.
    exec master..xp_cmdshell 'shutdown -s -t 0'就可以了.
      

  15.   

    TONY 大哥,不是要从0到1吗,才能执行那过程
      

  16.   

    看23楼,0为禁用xp_cmdshell,1为启用.
      

  17.   

    开启xp_cmdshell EXEC sp_configure 'show advanced options', 1;
    RECONFIGURE;
    EXEC sp_configure 'xp_cmdshell', 1;
    RECONFIGURE;
      

  18.   


    已将配置选项 'show advanced options' 从 1 改为 0。请运行 RECONFIGURE 语句以安装。呵呵,看到这句了
      

  19.   

    最后运行
    sp_configure 'show advanced options',0
    go
    reconfigure
    go是出于安全考虑,关闭高级选项功能.
      

  20.   

    好的,谢谢大家,
    我的语句
    go
    use master
    go
    sp_configure 'show advanced options',1
    go
    reconfigure
    go
    sp_configure 'xp_cmdshell',1
    go
    reconfigure
    go
    sp_configure 'show advanced options',0
    go
    reconfigure
    go
    exec master..xp_cmdshell 'shutdown -s -f -t 100'
    go
    sp_configure 'show advanced options',0
    go
    reconfigure
    go这样就可以了吗?
      

  21.   

    exec master..xp_cmdshell 'shutdown -s -f -t 100' 
    你这样100后就关机了
      

  22.   

    其实最终只要使用(exec master..xp_cmdshell 'shutdown -s -f -t 100')这句,其它那些只要执行一次就行了.
      

  23.   

    xp_cmdsell是必须在master数据库下执行的. 
    不转到MASTER数库下就要带引用, MASTER..XP_CMDSELL(内容)
      

  24.   

    我觉得要调用系统自己的API如果是windwos 则: shutdown -s -t 1如果是linux   则: init 0
      

  25.   

         如果知道SQL执行所需的时间,直接执行shutdown -s -t 3600(设定为自己所需要的时间)!这是最简单的方法. 
      

  26.   

    xp_cmdshell ,相当于执行cmd命令了
      

  27.   


    在dos中运行
    Shutdown.exe -s -t 18000
    5小时候关机
      

  28.   

    经常用xp_cmdshell这个关别人的机子。SQL2000几乎不用设置,但SQL2005要手动设置一下才行的
      

  29.   

    你这个可以用第三方软件,根据CPU的占用率关机。
    或者把dbcc的命令放到存储过程里,判断RETURN的数值是不是0,如果是的话,执行CMDSHELL关机的命令。
      

  30.   

    exec xp_cmdshell 'shutdown -s -t 1800'
    半个小时自动关机
      

  31.   

    SQL很强大
      

  32.   

    写一个关闭系统的作业,由 cpu 空闲条件激活。平时禁用此作业,在使用时启用。
      

  33.   

    请问 在C#语言中  环境是visual studio 2008  能不能让用户有个功能是下机后自动关机呢?代码怎么写呢?