Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Execute a DTS package in a Etored Procedure 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Right Now I run it manually. I open the Database find “Data Transformation Service” in the folder list and then find My package “CopyPartmaster”. I right click on it and click “Execute” this works good but I would like to automate it more.
Then go to a Stored Procedure I created which does the second part of the Parts upload.
The Line In My SP is
EXEC [Update Copy Partmaster]

I would like to put above that line a command which would run my DTS package and then run the "EXEC [Update Copy Partmaster]" line like so:

Run DTS [CopyPartmaster] //< whatever the correct syntax is
EXEC [Update Copy Partmaster]

TIA
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
OK I got this

DTSRun /~S 0xDCC540F09BFED1009DE252DA2ECDE50D3473ED7DF542C632921B1EAB0BAB9FD7 /~U 0xD461B5B88CB2AAECEA00876768403E5226BAE8A75E1302EE /~P 0xF6FCCE8AF4D9EA31978BF11E2B2E32A8 /~N 0x5B92B8FE0B241CBFF9129C0F6A1508EABE486152C185288C4EAB76DFE6581D58

It gives an error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '/'.


DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Rather than create a stored procedure and scheduling the stored procedure why not schedule the DTS package directly by right clicking on the package and selecting schedule package !

If you really want to run it from a stored procedure you could should still create a scheduled job for the DTS package and then use the stored procedure:

msdb..sp_start_job

to manually start the schedule job from your SP.

NOTE:
DTSRun is not a TSQL command and cannot be used directly in a stored procedure.
You will notice in the Job step that is a cmdExec operating system command.


Chris Dukes
 
Here is what I got.

USE msdb
EXEC sp_start_job @job_name = ‘CopyPartMaster'

OK it works but it takes 4 minutes to complete
So I need a delay or say 5-10 minutes between commands
like so:

USE msdb
EXEC sp_start_job @job_name = ‘CopyPartMaster'
//'need delay or 5-10 min. here
USE universal1
EXEC [Update Copy Partmaster]

If the second procedure runs too soon, I get NO records beacuse the first one has not made them all yet.

Any Ideas????


DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
you can use xp_sqlagent_enum_jobs to determine when the job has finished.

Read the values returned by xp_sqlagent_enum_jobs before you start the job and loop round until the values change (ie the job has completed.

-- need to read values first
-- into @iLastRunTimeOrg and @@iLastRunTimeOrg
WHILE (@iLastRunTime = @iLastRunTimeOrg AND
@iLastRunDate = @@iLastRunTimeOrg )
BEGIN
-- Wait for 4 Seconds
WAITFOR DELAY '00:00:4'


INSERT INTO #xp_results
EXECUTE master.dbo.xp_sqlagent_enum_jobs @is_sysadmin, @job_owner

SELECT @iLastRunDate = Last_Run_Date,
@iLastRunTime = Last_Run_Time
FROM #xp_results
WHERE job_id = @uiJobID

DELETE FROM #xp_results

END


hope this helps,

chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top