ASP
  Home arrow ASP arrow Page 5 - Creating DTS Packages With SQL Server 2000
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Creating DTS Packages With SQL Server 2000
By: Tim Pabst
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 244
    2002-02-01

    Table of Contents:
  • Creating DTS Packages With SQL Server 2000
  • What is a DTS package?
  • Creating a DTS package
  • Exporting the results set to a text file
  • Executing our DTS package in ASP
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating DTS Packages With SQL Server 2000 - Executing our DTS package in ASP


    (Page 5 of 6 )

    Thanks to the way everything in Windows is tightly integrated, we only need a couple of lines to execute our DTS package. We need to instantiate a new DTS package object. The DTS package object is a COM object with the ProgID of "DTS.Package". Once we have instantiated a new DTS package object, we can pass-in our global variable (for the WHERE clause), and execute each step in our DTS package sequentially.

    Create a new ASP script called "testdtspkg.asp" and enter the following code into it:

    <html>

    <head>

    <title>Sales Report DTS Package</title>

    </head>

    <body bgcolor="#FFFFFF">

    <%

    dim objDTSPackage

    dim objDTSStep

    dim strResult

    dim blnSucceeded

    const DTSSQLStgFlag_Default = 0

    const DTSStepExecResult_Failure = 1

    set objDTSPackage = Server.CreateObject("DTS.Package")

    blnSucceeded = true

    objDTSPackage.LoadFromSQLServer "(local)", "sa", "", DTSSQLStgFlag_Default, "", "", "", "SalesPkg"

    objDTSPackage.GlobalVariables("gPaymentTerm").Value = "Net 30"

    objDTSPackage.Execute

    for each objDTSStep in objDTSPackage.Steps

    if objDTSStep.ExecutionResult = DTSStepExecResult_Failure then

    strResult = strResult & "Package " & objDTSStep.Name & " failed.<br>"

    blnSucceeded = false

    else

    strResult = strResult & "Package " & objDTSStep.Name & " succeeded.<br>"

    end if

    next

    if blnSucceeded then

    Response.Write "<h1>Package Succeeded</h1>"

    else

    Response.Write "<h1>Package Failed</h1>"

    end if

    Response.Write strResult



    %>

    </body>

    </html>


    The DTS.Package object has a LoadFromSQLServer method that lets us load our DTS package. It's signature looks like this:

    LoadFromSQLServer ServerName, Username, Password, Flags, PackagePassword, PackageGUID, PackageVersionGUID, Package Name, PersistsHost

    As you can see in our example above, several of the parameters are optional. Once we have loaded our package, we have to assign a value to its global variable, gPaymentTerm. Remember that this global variable will replace the "?" in the WHERE clause of our query to the sales and stores tables of the pubs database? We use the GlobalVariables collection to do this:

    objDTSPackage.GlobalVariables("gPaymentTerm").Value = "Net 30"

    Next, we use the Steps collection of our DTS package object to execute each step in our DTS package sequentially. First step is the OLEDB connection, then the execute SQL task, and lastly the ActiveX script task. For each step, we check whether it succeeded/failed using its ExecutionResult variable and note this in the strResult string variable. If a step fails, then the blnSucceeded variable is set to false.

    Lastly, we output whether or not our DTS package succeeded/failed, as well as the details of each step that it contains. When I ran the script in my browser, it gave me the following results:

    Executing our DTS package in ASP

    Notice that only the tasks are listed here, and not the actual connection object. In our example, the sales email was sent to tim@devarticles.com and mitchell@devarticles.com. Here's a snippet from the email attachment (c:\salesreport.txt):

    Store #7066 sold 50 items with payment type Net 30

    Store #7067 sold 40 items with payment type Net 30

    Store #7067 sold 20 items with payment type Net 30

    More ASP Articles
    More By Tim Pabst


       · Hi, Went thru the article. Was exactly the one I was looking for. It helped me a...
       · Real this article helped me a lot......thank you
       · Ditto from the other two comments. It was just what I was looking...
       · Firstly, the article is very descriptive & helpful but I m messed up with the SQL...
       · dts is now SSIS in 2005 or later versions of sql server , the artcle is for creating...
     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT