creating job with ssis step using tsql - tsql

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

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.

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.

Related

Talend Run If Trigger with context variables

I have a question regarding the output of a job.
Would it be possible to make an output of a job dynamic?
What I mean is being able to configure a wanted output via a property or something? The user should be able to choose in what kind of database he wants the data to be imported by modifying a property.
Apparently, this can be done using a runIf - I unfortunately could not figure out how to do that.
The run if can only be used for booleans. For instance when a condition is met, the existence (or non-existence) of a file, if the number of rows returned is greater than 100, and countless other conditions.
How would it be possible the check if the context variable equals a specific String? For instance, if context.test = "postgres" then tpostgresqloutput, if context.test = "snowflake" then tsnowflakeoutput?
e.g.
job > tPostgresqlOutput > run if > context.test = "postgres"
job > tsnowflakeoutput > run if > context.test = "snowflake"
Thanks,
BR
For String comparison in RunIf, you can use:
context.test.equalsIgnoreCase("postgres")
You may want to connect the appropriate dataflow to the above RunIf depending on whether it is postgres or snowflake.

Is there a way to use User Activity Variables to store SQL in Datastage

I am considering using RCP to run a generic datastage job, but the initial SQL changes each time it's called. Is there a process in which I can use a User Activity Variable to inject SQL from a text file or something so I can use the same datastage?
I know this Routine can read a file to look up parameters:
Routine = ‘ReadFile’
vFileName = Arg1
vArray = ”
vCounter = 0
OPENSEQ vFileName to vFileHandle
Else Call DSLogFatal(“Error opening file list: “:vFileName,Routine)
Loop
While READSEQ vLine FROM vFileHandle
vCounter = vCounter + 1
vArray = Fields(vLine,’,’,1)
vArray = Fields(vLine,’,’,2)
vArray = Fields(vLine,’,’,3)
Repeat
CLOSESEQ vFileHandle
Ans = vArray
Return Ans
But does that mean I just store the SQL in one Single line, even if it's long?
Thanks.
Why not just have the SQL within the routine itself and propagate parameters?
I have multiple queries within a single routine that does just that (one for source and one for AfterSQL statement)
This is an example and apologies I'm answering this on my mobile!
InputCol=Trim(pTableName)
If InputCol='Table1' then column='Day'
If InputCol='Table2' then column='Quarter, Day'
SQLCode = ' Select Year, Month, '
SQLCode := column:", Time, "
SQLCode := " to_date(current_timestamp, 'YYYY-MM-DD HH24:MI:SS'), "
SQLCode := \ "This is example text as output" \
SQLCode := "From DATE_TABLE"
crt SQLCode
I've used the multiple encapsulations in the example above, when passing out to a parameter make sure you check the ', " have either been escaped or are displaying correctly
Again, apologies for the quality but I hope it gives you some ideas!
You can give this a try
As you mentioned ,maintain the SQL in a file ( again , if the SQL keeps changing , you need to build a logic to automate populating the new SQL)
In the Datastage Sequencer , use a Execute Command Activity to open the SQL file
eg : cat /home/bk/query.sql
In the job activity which calls your generic job . you should map the command output of your EC activity to a job parameter
so if EC activity name is exec_query , then the job parameter will be
exec_query.$CommandOuput
When you run the sequence , your query will flow from
SQL file --> EC activity-->Parameter in Job activity-->DB stage( query parameterised)
Has you thinked to invoke a shellscript who connect to database and execute the SQL script from the sequential job? You could use sqlplus to connect in the shellscript and read the file with the SQL and use it. To execute the shellscript from the sequential job use a ExecCommand Stage (sh, ./, ...), it depends from the interpreter.
Other way to solve this, depends of the modification degree of your SQL; you could invoke a routine base who handle the parameters and invokes your parallel job.
The principal problem that I think you could have, is the limit of the long of the variable where you could store the parameter.
Tell me what option you choose and I could help you more.

MVS OS-390 - How do I Capture Job Information from CA-JOBTRAC programmatically

I am using REXX to invoke JOBTRAC programmatically which works however I am unable to pass JOBNAME arguments using this approach. Can this be done using REXX?
The idea is to find the history of the job run using the program jobtrac. We use jobtrac's schedule to find the history of when job runs happened. We invoke jobtrac using
‘TSO JOBTRAC’ AND SUPPLY history command ‘H XXXXXX’ in the command line (XXXXX – jobname)
I was thinking to route the jobtrac info to a flat file and parse it so that I can do some reporting real time during the job run. The above problem is also linked to this following scenario:
If I give dslist 'DSLIST A.B.C.*'’ in the ISPF panel
It gives the series of datasets ...
A.B.C.A,
A.B.C.D
A.B.C.E
When I give
"SAVE ORANGE"
it stores this list under
MYUSERID.ORANGE.DATASETS.
I know this can be automated pro grammatically and I have seen that . But I don’t have the code base to do that right now. This is much similar to the jobtrack issue I have.
Here is some REXX CODE to help with understanding. I know this code is wrong…we cannot use outtrap for this as it is used to get console output.
say 'No. of month end jobs considered for history :'jobnames.0
if jobnames.0 > 0 then do
do i = 1 to jobnames.0
say jobnames.i
jobname = Word(jobnames.i,1);
say 'jobname under consideration is ' jobname;
tsocmd="JOBTRAC;ADDLOC=000;H "|| strip(jobname);
say 'tso command is ' tsocmd;
y = outtrap(jobdetails.)
Address TSO "'tsocmd'" ------------------> wrong…I believe I have to use ispexec
say 'job details are ' jobdetails.6;
end;

Unable to execute an oracle update statement within perl

I have a problem in a perl script that I'm writing. When I run the script it hangs after prepare(). I've tried to run the update statement from SQL Developer and it works fine.
I've also tried to print out all parameters and they are correct.
What am I missing here?
my $upd = 'update ngs.pp_subscr_data set address=?, city=?, postalcode=?, kennitala=?, email=?, firstname=?, lastname=?, last_upd=systimestamp where snb=?';
my $s = $dbh->prepare ($upd) || exitError(-9802, 'Couldn\'t prepare update statement.');
$s->execute($addr, $city, $pcode, $ktala, $email, $fname, $lname, $snb) || exitError(-9803, 'Couldn\'t execute statement: ' . $s->errstr);
Thanks.
First, what version of Oracle?
Ok, I see couple of problems with your description. When you say "hang", is it really a hang? Could it be spinning?
Also, second, you say "... it hangs after prepare()". Does that mean it hangs after you call prepare(), or after it returns from prepare()?
Is it hanging in the database, and your client program is waiting for a database call to complete?
You need to run the program, then look at V$SESSION, identify the SID that corresponds to the database session of your program, and see what it's doing. Look at the EVENT column in V$SESSION. Also, look at the STATUS column to tell if the session is currently in a database call (ACTIVE), or waiting for the client program to call the database (INACTIVE).
Report some information back, and I may be able to provide further insight.
Hope that helps.

Using SSIS Task Exec SQL task with sp_send_mail

I have a SSIS package which loops through a number of people then attaches a set of links to reports as attachments.
This all works fine with the Send mail task until I hit the 4,000 character limit :(
So I am trying to get this to work with the Execute SQL task, using sp_send_mail
I am trying something simple first but I cannot get it to work
Paramater : User::strPersonName
Direction : Input
Data Type : VarChar
Size : -1
SQL Statement =
DECLARE #bodytext AS VARCHAR(200)
SET #bodytext = 'Good Morning' + ?
EXEC msdb.dbo.sp_send_dbmail
#profile_name = 'Shoop',
#recipients = 'moonbase#hatstand.com',
#subject = '1',
#body = #bodytext
I am getting the resultset not properly set up generic error
Any ideas? :(
Instead of using sp_send_mail, you could still use the send mail task from SSIS. The 4000 character limit that I believe you are talking about, when populating your message, is on the expression, not on the variable itself. If you are using a MessageSourceType of variable in the send mail task, you can use the script task to build your message body (allowing you to create a string larger than 4000 characters).
Edit: Since the problem is with your attachments, I see one thing that could be a problem with the SQL for your Execute SQL task, according to http://technet.microsoft.com/en-us/library/ms140355.aspx , you should use "?" as the parameter marker for ADO connections and "#" for ADO.NET, but it seems like you're using both.
As another alternative, here's a blog on how to use the script task and .NET to send your email. http://www.mssqltips.com/sqlservertip/1753/sending-html-formatted-email-in-sql-server-using-the-ssis-script-task/
You shoudn't need a result set, but if you do make sure it is set correctly in the General tab in the SQL Task. From my understanding you are just passing in parameter data and not returning anything, so I think you have it set to Single Row instead of None.