Reputation: 2909
Based on the example here from MSDN, how could one provide SSIS package level variables if one were to invoke the package via "sp_start_job" procedure?
Here is the example code from MSDN:
Dim jobConnection As SqlConnection
Dim jobCommand As SqlCommand
Dim jobReturnValue As SqlParameter
Dim jobParameter As SqlParameter
Dim jobResult As Integer
jobConnection = New SqlConnection("Data Source=(local);Initial Catalog=msdb;Integrated Security=SSPI")
jobCommand = New SqlCommand("sp_start_job", jobConnection)
jobCommand.CommandType = CommandType.StoredProcedure
jobReturnValue = New SqlParameter("@RETURN_VALUE", SqlDbType.Int)
jobReturnValue.Direction = ParameterDirection.ReturnValue
jobCommand.Parameters.Add(jobReturnValue)
jobParameter = New SqlParameter("@job_name", SqlDbType.VarChar)
jobParameter.Direction = ParameterDirection.Input
jobCommand.Parameters.Add(jobParameter)
jobParameter.Value = "RunSSISPackage"
jobConnection.Open()
jobCommand.ExecuteNonQuery()
jobResult = DirectCast(jobCommand.Parameters("@RETURN_VALUE").Value, Integer)
jobConnection.Close()
Select Case jobResult
Case 0
Console.WriteLine("SQL Server Agent job, RunSISSPackage, started successfully.")
Case Else
Console.WriteLine("SQL Server Agent job, RunSISSPackage, failed to start.")
End Select
Console.Read()
How can I supply values to the variables inside the SSIS package named "RunSSISPackage"?
Upvotes: 2
Views: 2902
Reputation: 96552
We change our variable values dynamically at run time through the use of a configuration table or a configuration file. We don't let users run our SSIS packages, but I suppose your job could have a step that first updates the config file and then runs the package.
Upvotes: 0
Reputation: 103579
you could create a table to act like a queue, where you insert a row containing your parameters and then start the job. Within the TSQL that then runs, just select out the values and mark the queue row "C"ompleted or just delete it and be on your way.
EDIT
try looking at Running SSIS package programmatically which covers all of the following methods:
Upvotes: 2