loLoading and Running a Local Package Programmatically

  1. Start the Visual Studio development environment, and create a new application in your preferred development language. This example uses a console application; however you can also run a package from a Windows Forms application, an ASP.NET Web form or Web service, or a Windows service.

  2. On the Project menu, click Add Reference and add a reference to Microsoft.SqlServer.ManagedDTS.dll. Click OK.

  3. Use the Visual Basic Imports statement or the C# using statement to import the Microsoft.SqlServer.Dts.Runtime namespace.

  4. Add the following code in the main routine. The completed console application should look like the following example.

    Note:
    The sample code demonstrates loading the package from the file system by using the LoadPackage method. However you can also load the package from the MSDB database by calling the LoadFromSqlServer method, or from the Integration Services package store by calling the LoadFromDtsServer method.
  5. Run the project. The sample code executes the CalculatedColumns sample package that is installed with the SQL Server 2005 samples. The result of package execution is displayed in the console window.

Sample Code


using  System;
using  Microsoft.SqlServer.Dts.Runtime;

namespace  RunFromClientAppCS
{
  
class  Program
  {
    
static   void  Main( string [] args)
    {
      
string  pkgLocation;
      Package pkg;
      Application app;
      DTSExecResult pkgResults;

      pkgLocation 
=
        
@" C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services "   +
        
@" \Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx " ;
      app 
=   new  Application();
      pkg 
=  app.LoadPackage(pkgLocation,  null );
      pkgResults 
=  pkg.Execute();

      Console.WriteLine(pkgResults.ToString());
      Console.ReadKey();
    }
  }
}

你可能感兴趣的:(package)