简体   繁体   English

如何在我的 SQL 服务器代理作业中创建一个步骤,它将运行我的 SSIS package?

[英]How do I create a step in my SQL Server Agent Job which will run my SSIS package?

I'm trying to create an automated job for the SQL Server Agent to run.我正在尝试为 SQL 服务器代理创建一个自动化作业以运行。 The job is supposed to run my SSIS package.该作业应该运行我的 SSIS package。

Here's what I have so far:这是我到目前为止所拥有的:

EXEC sp_add_job @job_name = 'My Job'
            ,@description = 'My First SSIS Job'
            ,@job_id = @jobid OUTPUT

EXEC sp_add_jobstep @job_id =@jobid
                    ,@step_name = N'Upload Data'
                    ,@step_id = 1
                    ,@command=N'/FILE "D:\Installs\Upload.dtsx"'
EXEC sp_add_jobstep @job_id = @jobid
                    ,@step_name = N'Download Data'
                    ,@step_id = 2
                    ,@command=N'/FILE "D:\Installs\Download.dtsx"'

Unfortunately when I run this, I get an error saying不幸的是,当我运行它时,我收到一条错误消息

Incorrect syntax near '/' '/' 附近的语法不正确

I suspect it's complaining about the /FILE in my command.我怀疑它在抱怨我的命令中的/FILE

I can't find documentation about the appropriate syntax to use within @command anywhere -- I pulled /FILE out of some old code I found somewhere.我在任何地方都找不到关于在@command 中使用的适当语法的文档——我从某处找到的一些旧代码中提取了/FILE What is the correct syntax for running an SSIS package in a job?在作业中运行 SSIS package 的正确语法是什么?

I ran the SQL script in the question but didn't encounter any errors.我在问题中运行了 SQL 脚本,但没有遇到任何错误。 So, I am not sure what is causing the error in your case.因此,我不确定是什么导致了您的错误。 However, if you have access to SQL Server Agent through SQL Server Management Studio.但是,如果您可以通过 SQL Server Management Studio 访问SQL Server Agent Here are the steps to create a job using the Graphical User Interface.以下是使用图形用户界面创建作业的步骤。

  1. Go to SQL Server Management Studio. Go 到 SQL 服务器管理工作室。 Expand SQL Server Agent and right-click on Jobs, then select New Job... as shown in screenshot # 1 .展开SQL Server Agent并右键单击作业,然后单击 select New Job...如屏幕截图 # 1所示。

  2. Provide a name and Owner by default will be the account that creates the job but you can change it according to your requirements.提供名称,默认情况下所有者将是创建作业的帐户,但您可以根据您的要求进行更改。 Assign a Category if you would like to and also provide a description.如果您愿意,请指定一个类别并提供描述。 Refer screenshot # 2 .参考截图# 2

  3. On the Steps section, click New... as shown in screenshot # 3 .在 Steps 部分,单击New...如屏幕截图 # 3所示。

  4. On the New Job Step dialog, provide a Step name.在“新建作业步骤”对话框中,提供步骤名称。 Select SQL Server Inegration Services Package from Type. Select SQL Server Inegration Services Package从类型。 This step will run under SQL Agent Service Account by default.此步骤将默认在SQL Agent Service Account下运行。 Select the package source as File system and browse to the package path by clicking on ellipsis. Select package 源作为File system并通过单击省略号浏览到 package 路径。 This will populate the Package path.这将填充 Package 路径。 Refer screenshot # 4 .参考截图# 4 If you don't want the step to execute under the SQL Agent Service Account , then refer the steps # 8 - 9 to know how you can use a different account.如果您不希望在SQL Agent Service Account下执行该步骤,请参阅步骤 # 8 - 9以了解如何使用其他帐户。

  5. If you have a SSIS configuration file (.dtsConfig) for the package, click on the Configurations tab and add the Configuration file as shown in screenshot # 5 .如果您有 package 的 SSIS 配置文件 (.dtsConfig),请单击配置选项卡并添加配置文件,如屏幕截图 # 5所示。

  6. Click OK and there is the package in step 1 as shown in screenshot # 6 .单击确定,在步骤 1 中有 package,如屏幕截图 # 6所示。 Similarly, you can create different steps.同样,您可以创建不同的步骤。

  7. Once the job has been created, you can right-click on the job and select Script Job as --> CREATE To --> New Query Editor Window to generate the script as shown in screenshot # 7 .创建作业后,您可以右键单击作业和 select Script Job as --> CREATE To --> New Query Editor Window以生成脚本,如屏幕截图 # 7所示。

  8. To run the SSIS step under different account, on the Management Studio, navigate to Security --> right-click on Cedentials --> select New Credential... as shown in screenshot # 8 .要在不同的帐户下运行 SSIS 步骤,请在 Management Studio 上导航至Security --> right-click on Cedentials --> select New Credential...如屏幕截图 # 8所示。

  9. On the New Credential dialog, provide a Credential name, Windows account and Password under which you would like to execute SSIS steps in SQL jobs.New Credential对话框中,提供一个 Credential 名称、Windows 帐户和 Password,您希望在 SQL 作业中执行 SSIS 步骤。 Refer screenshot # 9 .参考截图# 9 Credential will be created as shown in screenshot # 10 .将创建凭证,如屏幕截图 # 10所示。

  10. Next, we need to create a proxy.接下来,我们需要创建一个代理。 On the Management Studio, navigate to SQL Server Agent --> Proxies --> right-click on SSIS Package Execution --> select New Proxy... as shown in screenshot # 11 . On the Management Studio, navigate to SQL Server Agent --> Proxies --> right-click on SSIS Package Execution --> select New Proxy... as shown in screenshot # 11 .

  11. On the New Proxy Account window, provide a Proxy name, select the newly created Credential, provide a description and select SQL Server Integration Services Package as shown in screenshot # 12 . On the New Proxy Account window, provide a Proxy name, select the newly created Credential, provide a description and select SQL Server Integration Services Package as shown in screenshot # 12 . Proxy account should be created as shown in screenshot # 13 .应该创建代理帐户,如屏幕截图 # 13所示。

  12. Now, if you go back to the step in SQL job, you should see the newly created Proxy account in the Run as drop down.现在,如果您 go 回到 SQL 作业中的步骤,您应该会在Run as下拉菜单中看到新创建的代理帐户。 Refer screenshot # 14 .参考截图# 14

Hope that helps.希望有帮助。

Screenshot #1:截图#1:

1

Screenshot #2:截图#2:

2

Screenshot #3:截图#3:

3

Screenshot #4:截图#4:

4

Screenshot #5:截图#5:

5

Screenshot #6:截图#6:

6

Screenshot #7:截图#7:

7

Screenshot #8:截图#8:

8

Screenshot #9:截图#9:

9

Screenshot #10:截图#10:

10

Screenshot #11:截图 #11:

11

Screenshot #12:截图#12:

12

Screenshot #13:截图#13:

13

Screenshot #14:截图#14:

14

If you're building the job using the sp_add... procs, I think you need to explicitly set the subsystem to be called, a la如果您正在使用 sp_add... procs 构建作业,我认为您需要显式设置要调用的子系统,例如

EXEC sp_add_jobstep @job_id = @jobid,
@step_name = N'Upload Data',
@step_id = 1,
@subsystem = 'DTS',
@command=N'/FILE "D:\Installs\Upload.dtsx"'

This is equivalent to @Siva's Screenshot #4 'Type'='SQL Server Integration Services Package'.这相当于@Siva 的屏幕截图#4 'Type'='SQL Server Integration Services Package'。

See this MSDN article for the complete list of subsystems.有关子系统的完整列表,请参阅MSDN 文章。

EDIT : 'TSQL' is the default, so your current setup is trying to execute '/FILE "D:\Installs\Upload.dtsx"' as a T-SQL command.编辑: 'TSQL' 是默认设置,因此您当前的设置正在尝试将 '/FILE "D:\Installs\Upload.dtsx"' 作为 T-SQL 命令执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM