欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

自动开始SQL的Agent代理

程序员文章站 2024-01-31 20:00:46
...

自动开始SQL的Agent代理 Agent -- sp_sqlagent_autostart-- created by gertd@sqldev.net-- NOTE: works on NT/Win2K/WinXP only, not in Win9x--use mastergo if exists (select * from sysobjects where name = 'sp_sqlagent_autostart' and type = 'P') dr

自动开始SQL的Agent代理 Agent
-- sp_sqlagent_autostart
-- created by gertd@sqldev.net
-- NOTE: works on NT/Win2K/WinXP only, not in Win9x
--
use master
go 

if exists (select * from sysobjects where name = 'sp_sqlagent_autostart' and type = 'P')
    drop proc dbo.sp_sqlagent_autostart
go

create proc dbo.sp_sqlagent_autostart
as
set nocount on

declare @service nvarchar(128)

if (charindex(N'7.00', @@version, 0) > 0)
begin
    select @service = N'SQLServerAgent'
end

if (charindex(N'8.00', @@version, 0) > 0)
begin
    if (serverproperty('instancename') is null)
        select @service = N'SQLServerAgent'
    else
        select @service = N'SQLAgent$' + convert(nvarchar(128), serverproperty('InstanceName'))
end

exec master.dbo.xp_servicecontrol 'START', @service
go

exec master.dbo.sp_procoption 'sp_sqlagent_autostart', 'startup', 'true'
go