【问题标题】:configuring sql server job agent配置 sql server 作业代理
【发布时间】:2013-01-15 04:00:08
【问题描述】:

我正在尝试使用以下脚本配置 SQL Server 作业代理:

USE [msdb]
GO
CREATE USER [mydbuser] FOR LOGIN [mydbuser]
GO
EXEC sp_addrolemember N'db_datareader', N'mydbuser'
GO
EXEC sp_addrolemember N'SQLAgentOperatorRole', N'mydbuser'
GO
EXEC sp_addrolemember N'SQLAgentReaderRole', N'mydbuser'
GO
EXEC sp_addrolemember N'SQLAgentUserRole', N'mydbuser'
go
sp_configure 'show advanced options',1
go
reconfigure with override
go
      sp_configure 'xp_cmdshell',1
go
reconfigure with override
go
sp_configure 'show advanced options',0
go
reconfigure with override


use master
go
GRANT EXECUTE on xp_cmdshell to db_job
go

use master
go
EXEC sp_xp_cmdshell_proxy_account 'mydomain\db_job', 'password-1'
go

CREATE CREDENTIAL [Job3] WITH IDENTITY = N'mydomain\mydomainuser', SECRET =               N'mydomain\mydomainuser'
GO

USE [msdb]
GO
EXEC msdb.dbo.sp_add_proxy @proxy_name=N'LW_JobRunner',@credential_name=N'Job', 
@enabled=1
GO
EXEC msdb.dbo.sp_grant_proxy_to_subsystem @proxy_name=N'LW_JobRunner', @subsystem_id=3
GO
EXEC msdb.dbo.sp_grant_login_to_proxy @proxy_name=N'LW_JobRunner',         @login_name=N'mydbuser'
GO

/* Setting up job Category */

DECLARE @ReturnCode INT
SELECT @ReturnCode = 0

EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL',             @name=N'MyJob'
go

USE MASTER
GO

EXEC master.dbo.xp_sqlagent_proxy_account N'SET',
     N'DEV',            -- agent_domain_name
     N'Administrator',  -- agent_username
     N'password'        -- agent_password 

但是执行sp xp_sqlagent_proxy_account 的最后一步,说

找不到存储过程 xp_sqlagent_proxy_account。

我确定我正在使用sa 凭据在master db 上执行它...

因此,在添加作业时,我会收到类似这样的错误

在 sys.servers 中找不到服务器“myIpAddress”。验证 指定了正确的服务器名称。如有必要,执行 存储过程 sp_addlinkedserver 将服务器添加到 sys.servers

如何解决这个问题?

【问题讨论】:

    标签: sql-server sql-server-2008 jobs


    【解决方案1】:

    当非系统管理员用户尝试执行 xp_cmdshell 时,通常会发生此错误。但是,您声明您确定您正在使用 sa 凭据在主数据库中执行。

    你可能想尝试运行这个:

    -- Enable non-system administrators to run the job and to execute xp_cmdshell.
    EXECUTE msdb..sp_set_sqlagent_properties @sysadmin_only = 0
    GO
    

    这将允许非 sa 用户访问 xp_cmdshell。如果它可以正常工作,则意味着运行脚本的用户帐户是非 sa 帐户。

    希望这会有所帮助。

    拉吉

    【讨论】:

    • 我收到以下错误@@sysadmin_only 标志不再受 SQLAgent 支持,保留此处只是为了向后兼容
    • 你是对的。由于您的问题没有谈到 SQL 版本,所以我提出了一个通用的建议。我刚刚注意到 SQL 2008 标签。对不起
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2017-11-11
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多