如何在 SQL Server 代理作业中创建将运行 SSIS 包的步骤?

发布于 2024-11-24 09:25:22 字数 824 浏览 0 评论 0原文

我正在尝试创建一个自动化作业供 SQL Server 代理运行。该作业应该运行我的 SSIS 包。

到目前为止,这是我所得到的:

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"'

不幸的是,当我运行这个时,我收到一条错误消息

“/”附近的语法不正确

我怀疑它在抱怨我的命令中的 /FILE

我无法找到有关在 @command 中使用的适当语法的文档 - 我从某处找到的一些旧代码中提取了 /FILE 。在作业中运行 SSIS 包的正确语法是什么?

I'm trying to create an automated job for the SQL Server Agent to run. The job is supposed to run my 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.

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. What is the correct syntax for running an SSIS package in a job?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-12-01 09:25:23

我运行了问题中的 SQL 脚本,但没有遇到任何错误。所以,我不确定是什么导致了你的情况的错误。但是,如果您可以通过 SQL Server Management Studio 访问 SQL Server Agent。以下是使用图形用户界面创建作业的步骤。

  1. 转到 SQL Server Management Studio。展开 SQL Server Agent 并右键单击“作业”,然后选择新建作业...,如屏幕截图 #1 所示。

  2. 提供名称和所有者,默认情况下将是创建作业的帐户,但您可以根据您的要求进行更改。如果您愿意,请分配一个类别并提供描述。请参阅屏幕截图#2

  3. 在“步骤”部分,单击新建...,如屏幕截图 #3 所示。

  4. 在“新建作业步骤”对话框中,提供步骤名称。从类型中选择SQL Server 集成服务包。默认情况下,此步骤将在 SQL Agent Service Account 下运行。选择包源作为文件系统,然后通过单击省略号浏览到包路径。这将填充包路径。请参阅屏幕截图#4。如果您不希望在 SQL 代理服务帐户下执行该步骤,请参阅步骤 #8 - 9< /strong> 了解如何使用不同的帐户。


  5. 如果您有该包的 SSIS 配置文件 (.dtsConfig),请单击配置选项卡并添加配置文件,如屏幕截图 #5 所示。< /p>

  6. 单击“确定”,即可出现步骤 1 中的包,如屏幕截图 #6 所示。同样,您可以创建不同的步骤。

  7. 创建作业后,您可以右键单击该作业并选择将作业脚本编写为 -->创建到-->新的查询编辑器窗口用于生成脚本,如屏幕截图#7所示。

  8. 要在不同帐户下运行 SSIS 步骤,请在 Management Studio 上导航到 Security -->右键单击 Cedentials -->选择新凭据...,如屏幕截图 #8 所示。

  9. 新建凭据对话框中,提供您要在 SQL 作业中执行 SSIS 步骤的凭据名称、Windows 帐户和密码。请参阅屏幕截图#9。将创建凭据,如屏幕截图 #10 所示。

  10. 接下来,我们需要创建一个代理。在 Management Studio 上,导航到 SQL Server Agent -->代理 -->右键单击 SSIS 包执行 -->选择新代理...,如屏幕截图 #11 所示。

  11. 在“新建代理帐户”窗口中,提供代理名称,选择新创建的凭据,提供说明并选择 SQL Server Integration Services Package,如屏幕截图 #12 所示。应创建代理帐户,如屏幕截图 #13 所示。

  12. 现在,如果您返回到 SQL 作业中的步骤,您应该会在运行方式下拉列表中看到新创建的代理帐户。请参阅屏幕截图#14

屏幕截图 #1:

1

屏幕截图 #2:

2

屏幕截图#3:

3

屏幕截图 #4:

4

屏幕截图 #5:

5

屏幕截图 #6:

6

屏幕截图 #7:

7

屏幕截图 #8:< /strong>

8

屏幕截图#9:

9

屏幕截图 #10:

10

屏幕截图 #11:< /strong>

11

屏幕截图 #12:

12

屏幕截图 #13:

13

屏幕截图 #14:

14

I ran the SQL script in the question but didn't encounter any errors. 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. Here are the steps to create a job using the Graphical User Interface.

  1. Go to SQL Server Management Studio. Expand SQL Server Agent and right-click on Jobs, then select New Job... as shown in screenshot #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.

  3. On the Steps section, click New... as shown in screenshot #3.

  4. On the New Job Step dialog, provide a Step name. Select SQL Server Inegration Services Package from Type. This step will run under SQL Agent Service Account by default. Select the package source as File system and browse to the package path by clicking on ellipsis. This will populate the Package path. Refer screenshot #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.

  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.

  6. Click OK and there is the package in step 1 as shown in screenshot #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.

  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.

  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. Refer screenshot #9. Credential will be created as shown in screenshot #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.

  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. Proxy account should be created as shown in screenshot #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. Refer screenshot #14.

Screenshot #1:

1

Screenshot #2:

2

Screenshot #3:

3

Screenshot #4:

4

Screenshot #5:

5

Screenshot #6:

6

Screenshot #7:

7

Screenshot #8:

8

Screenshot #9:

9

Screenshot #10:

10

Screenshot #11:

11

Screenshot #12:

12

Screenshot #13:

13

Screenshot #14:

14

就是爱搞怪 2024-12-01 09:25:23

如果您正在使用 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"'

这相当于 @Siva 的屏幕截图 #4 'Type'='SQL Server Integration Services Package' 。

有关子系统的完整列表,请参阅这篇 MSDN 文章。

编辑:“TSQL”是默认值,因此您当前的设置尝试将“/FILE“D:\Installs\Upload.dtsx””作为 T-SQL 命令执行。

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

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'.

See this MSDN article for the complete list of subsystems.

EDIT: 'TSQL' is the default, so your current setup is trying to execute '/FILE "D:\Installs\Upload.dtsx"' as a T-SQL command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文