Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how can I stop a DTS package programmatically?

Posted on 2010-08-19
9
Medium Priority
?
1,541 Views
Last Modified: 2013-11-30
Hi,  I would like to know how to cancel a DTS (SQL server 2000) package programmatically (using C# or VB.NET or Visual basic). the package is executed programmatically, not in SQL server job. there is a Stop method available for SSIS packages, but I could not find an equivalent one for DTS packages. I searched everywhere, but couldn't find a solution for it. any help would be appreciated. the package is executed by a support person and if it hangs for some reason, I would like provide a button to abort its execution, because support won't have access to database to kill it from Enterprise manager or Management studio. thanks in advance.
0
Comment
Question by:rkpavp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Expert Comment

by:incidental74
ID: 33481290
How is the package executed within the program? using the DTEXEC command?
0
 

Author Comment

by:rkpavp
ID: 33482920
the package is executed using the Microsoft DTS Object Library (COM API), as mentioned in the article http://www.c-sharpcorner.com/UploadFile/fbulovic/DTSnCS12062005072324AM/DTSnCS.aspx. it is urgent. Please let me know if you have any solution.
0
 
LVL 1

Expert Comment

by:incidental74
ID: 33516540
I was leaning more towards terminating the actual executable that runs the DTS package. It has been a while since I have worked with DTS, but no matter how the DTS package is executed, the executable that is responsible for running the package is DTEXEC or DTSRun, or something like that.

I was thinking that you could terminate the executable with a button after a certain period of time. Try running your program and watch on the server for a DTEXEC or DTSRun process in Task Manager pop up. You can use COM to then grab a hold of that handle and kill it.

Can you send some code over?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 30

Expert Comment

by:nmcdermaid
ID: 33516796
My thoughts also - termainte the executable. Problem is there is all sorts of cleanup that the database has to do anyway - i.e. you can end up with some kind of orphan process and you can make things worse.
If your package is hanging (amusing statement) then you would be better off working out why and fixing it.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33517300
>>If your package is hanging (amusing statement) then you would be better off working out why and fixing it.<<
I agree on all three counts.      :)

However, if you insist on terminating it, then consider KILLing the spid for the process instead of stopping the actual process.  It should prove to be less invasive.

0
 

Author Comment

by:rkpavp
ID: 33520759
thanks for all the replies. but if I kill the executable, will the changes made to the database be rolled back (or does it depend on if it is executed within a sql transaction) OR will it leave the data in partially committed state? I have seen that if I use the DTS COM object model API to execute the package, then it raises the onQueryCancel event periodically allowing the caller to cancel the package. so I was thinking if the user wishes to cancel the package, then set a flag in database and read that flag in onQueryCancel event handler and cancel the package accordingly, then it will terminate it gracefully. BUT there is another issue here. if I run the package using the code in the original link, then if it consumes too much memory, then it could cause recycling of web server application pool, so I have no choice but to execute the package using DTSRUN command, because it runs in a separate process from the webserver.
     can I get some sample code in C# OR VB.NET to execute a DTS package using DTSRUN (I guess I can't use DTEXEC because it is used only SSIS packages?) and also sample code to kill it if required. Please note that the package needs to be loaded from webserver file system, not from the database. Thanks in advance.
0
 
LVL 1

Accepted Solution

by:
incidental74 earned 1500 total points
ID: 33524338
DTSRun is just a command line utility, so executing it is as simple as using the Process.Start method in VB.Net (sorry not a C# guy, but I'm sure there is an equivalent). To help you build your DTSRun command line for the first time, you can use the DTSRunUI utility as explained here: http://www.sqldts.com/301.aspx.

After you execute DTSRun using Process.Start, the VB.Net program would not wait for DTSRun to finish before moving on to the rest of your code. That is, Process.Start would execute DTSRun asynchronously and your package would run on its own. That is where the WaitForExit method and HasExited property come into play.

To answer your question about rollbacks, it is kind of hard to say without knowing what your DTS package does. However, I do not think killing the process using DTSRun would rollback any work that may have been done by the DTS package. Nevertheless, upon killing the DTS package, it should kill and rollback any active SPIDs that are currently running from the package (at least that is how it works in SSIS).
Dim myProcess As Process = Process.Start("[Your DTSRun command line]")
myProcess.WaitForExit(10000)
' if the process doesn't complete within
' 10 seconds, kill it
If Not myProcess.HasExited Then
   myProcess.Kill()
End If

Open in new window

0
 

Author Closing Comment

by:rkpavp
ID: 33598389
the solution points me to the right direction and need to improve it to get the desired result. thanks a lot.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question