Executing DTS Packages using C#

Guess what! you can execute DTS Packages from C# code. Yeah I know its pretty cool. Take a look at the code below. Don't try to run this code as you need to do lot of modifications. Check out the link I have given at the bottom of this posting.

// This method will run the DTS Package
    private static void RunDTSPackage()
    {              
        // Name of the package to run
        string packageName = "AzamSharpDTSTesting";
        object pVarPersistStgOfHost = null; 

        DTS.PackageClass package = new DTS.PackageClass();
        package.LoadFromSQLServer("localhost","sa","azam123", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection
        , null, null, null, packageName, ref pVarPersistStgOfHost);

        try
        {
            // Execute the package
            Console.WriteLine("DTS Package Executing.."); 
            package.Execute();
            Console.WriteLine("DTS Package Completed");
           
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        finally
        {
            package.UnInitialize();
            package = null;
        }
        
    }

Check out this link: http://www.15seconds.com/issue/030909.htm

Print | posted @ Wednesday, October 19, 2005 8:29 PM

Twitter