问题
I would like to create sql server job using stored procedure and I can't seem to get it right. Integration Service Catologs -> SSIDB -> Cat1 ->Projects->999->Packages->999.dtsx
In step 1 properties of below script on Package tab "Server: and Package:" are empty, I need to populate these as well as set 32bit to true
Below is what I got, thanks in advance
EXECUTE msdb..sp_add_job @job_name = 'Job 1', @owner_login_name = SUSER_NAME(), @job_id = @JobId OUTPUT
EXECUTE msdb..sp_add_jobserver @job_id = @JobId, @server_name = @@SERVERNAME
EXECUTE msdb..sp_add_jobstep @job_id = @JobId, @step_name = 'Step1',@database_name = DB_NAME(), @on_success_action = 3 ,@subsystem = N'ssis'
, @command = N' "\SSISDB\Cat1\999\999.dtsx" @SERVER=N"@ServerName"'
EXECUTE msdb..sp_add_jobstep @job_id = @JobId, @step_name = 'Step2', @command = 'execute msdb..sp_delete_job @job_name="Job 1"'
EXECUTE msdb..sp_start_job @job_id = @JobId
回答1:
if anyone else comes across similar situation, easiest way to figure out how to create a job pragmatically is to create it using UI (Server Agent -> New Job). create everything you want to see, save it, then right click at the job Script Job As -> Create To -> New query and sql server will export the job as a query so you can see what you need to do.
回答2:
While we wait for clarification on the existing syntax, the two arguments to msdb..sp_add_jobstep
that you need to be concerned with are the @subsystem and @command.
, @subsystem = N'SSIS'
, @command = N'/ISSERVER "\"\SSISDB\POC\SSISConfigMixAndMatch\Package.dtsx\"" /SERVER "\".\dev2014\"" /X86 /Par "\"$ServerOption::LOGGING_LEVEL(Int16)\"";1 /Par "\"$ServerOption::SYNCHRONIZED(Boolean)\"";True /CALLERINFO SQLAGENT /REPORTING E'
The GUI will build out these options happily but you can read the dtexec documentation and come to the same script.
/ISSERVER
This specifies that we're using the fancy new execution engine built into the SSISDB- We pass in the package we want to execute to this option
- /SERVER where will these packages be found
- Specify the server name and optional instance
- /X86 As the fine documentation notes, this option only works for invocation from SQL Agent but this is how you specify you need to use the 32 bit dtexec.exe
- /Par Specify parameter values as needed
- Indicates our standard,
Basic
, level of logging - The next instance of /Par specifies whether the caller should wait for the process to complete (synchronous versus asynchronous process). Yes, the job steps should wait for the process to complete.
- /Reporting What information should be reported. This is odd because the useful information you used to get in an SQL Agent job report is no longer there. It will just say Consult the SSISDB reports for more information
- E, report Errors only.
来源:https://stackoverflow.com/questions/28565988/creating-job-with-ssis-step-using-tsql