【问题标题】:2012 SQL job problems2012 SQL作业问题
【发布时间】:2015-10-14 16:32:27
【问题描述】:

我在 SQL 2012 上度过了一段糟糕的时光。我习惯于使用 SQL 2000 进行作业调度和自动化,但我是 2012 年的新手。

我编写了一个非常基本的脚本(见下文),无论我做什么,脚本作为工作的第一步都失败了,但作为查询窗口中的独立查询可以正常工作。

任何帮助都会大有帮助。

declare @AccountID as int
declare @ID as int
declare @SaleDate as datetime
declare @todaysdate as datetime
declare @sentdate as datetime
declare @writeToFile as int
begin
set @todaysdate = getdate()
set @writeToFile = 0
select @id = ID, @AccountID = AccountID, @SaleDate = SaleDate from TransHeader where Transheader.ID = 19680
--print @@ROWCOUNT

select AccountID, max(SurveySent) as "THEFINALDATE" from tbl_survey_email where AccountID = @AccountID AND datediff(dd, SurveySent, @todaysdate) <= 182 Group By AccountID
set @writeToFile = @@ROWCOUNT
--print @writeToFile

if (@writeToFile = 0)
    begin

        insert into tbl_survey_email ('AccountID','TransactionID', 'datetime') VALUES (@AccountID, @ID, @SaleDate)
    end

end

经过数小时尝试一切以使其正常工作,它仍然无法正常工作。我什至将 SQL Server 代理服务更改为以我身份运行(域管理员)

我什至将我的脚本更改为仅是一个插入脚本,但仍然遇到几乎相同的错误。有任何想法吗?

【问题讨论】:

  • 您知道,通过正确的约束,您可以将整个作业重写为一条语句,对吧?

标签: sql sql-server sql-server-2012 sql-agent-job


【解决方案1】:

您必须授予 NT SERVICE 用户访问数据库中表的权限。您的 Keith 用户有权限,但 NT SERVICE 没有。它应该具有这样的权限:

当然,在我的屏幕截图中,用户与我认为的用户并不完全相同,但你明白了。

【讨论】:

  • 或者,更好的是,为作业设置一个特定用户。
猜你喜欢
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 2015-03-05
  • 1970-01-01
  • 2015-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多