2009-06-10 25 views

答えて

1

SQL Server 2000の一部であるData Transformation Serviceを参照している場合(これは、統合サービスに置き換えられて以降のバージョンでは使用できません)、いくつかの方法があります。

あなたのアプリケーションがサーバー上にある場合、それはあなたがまだDTSRunを使用することができ、サーバー上ではなく、あなたがマスターを使用して呼び出すストアド・プロシージャ内でない場合は、process.start

process.start("dtsrun /S ""server name"" /U sa /N ""d:\task.dts""") 

を使用してDTSRunからそれを実行することができます.dbo.xp_cmdshell、コード内でSPを呼び出します。 (xp_cmdshellを使用する場合は、開かれるセキュリティ上のリスクに注意する必要があります)。

また、あなたがこの記事を見て可能性があり、それはVBスクリプトからそれを行う方法について説明しますが、コードを簡単に変換できる:

https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5164094.html

0

これは何をすべきクラスのかなりの粗セットですVB.NetからDTSパッケージをプログラムで制御したい場合に必要です。私はそれが正しいか信頼できるかについて保証しませんが、始めるには十分な指針を与えるべきです。

ちょうどあなたのVisual Studioプロジェクトに(COM)ライブラリDTSPackageオブジェクトへの参照を追加

Option Explicit On 

輸入DTS 輸入System.Runtime.InteropServices

名前空間のテストに厳しいオプション パブリッククラスDTSRunner プライベートcpPointとしてComTypes.IConnectionPoint プライベートcpContainerとしてComTypes.IConnectio PackageEventsSinkとして整数としてnPointContainer プライベートintCookieが プライベートPES

Public Sub RunPackage(ByVal packageName As String) 

     Dim pkg As New DTS.PackageClass 
     pkg.LoadFromSQLServer("MySQLServer", String.Empty, String.Empty, DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, String.Empty, String.Empty, String.Empty, PackageName, System.Reflection.Missing.Value) 

     cpContainer = CType(pkg, ComTypes.IConnectionPointContainer) 
     cpContainer.FindConnectionPoint(New Guid("10020605-EB1C-11CF-AE6E-00AA004A34D5"), cpPoint) 
     PES = New PackageEventsSink 
     cpPoint.Advise(PES, intCookie) 
     AddHandler PES.OnPackageOnError, AddressOf PackageErroredHandler 
     AddHandler PES.OnPackageOnQueryCancel, AddressOf PackageQueryCancelHandler 
     pkg.Execute() 

     If cpPoint IsNot Nothing Then 
      cpPoint.Unadvise(intCookie) 
     End If 
     If Not pkg Is Nothing Then 
      pkg.UnInitialize() 
     End If 
     If PES IsNot Nothing Then 
      RemoveHandler PES.OnPackageOnError, AddressOf PackageErroredHandler 
      RemoveHandler PES.OnPackageOnQueryCancel, AddressOf PackageQueryCancelHandler 
     End If 
     PES = Nothing 
     cpContainer = Nothing 
     cpPoint = Nothing 
     pkg = Nothing 
    End Sub 

    Private Sub PackageErroredHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 
     If Not packageErrored Then 
      TraceEvent(TraceEventType.Error, -1, _ 
      "Error In DTS Package : {1} - {2} - {3} - {4}", _ 
      .EventSource, e.ErrorCode, e.Source, e.Description) 
      packageErrored = True 
     End If 
     e.Cancel = False 
    End Sub 

    Private Sub PackageQueryCancelHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 
     e.Cancel = False 
    End Sub 


    Private Class DTSEventArgs 
     Inherits EventArgs 

     Public EventSource As String 
     Public ErrorCode As Integer 
     Public Source As String 
     Public Description As String 
     Public Cancel As Boolean 
     Public PercentComplete As Integer = 0 

     Public Sub New(ByVal EventSource As String, ByVal Source As String, ByVal Description As String, ByVal ErrorCode As Integer, ByVal Cancel As Boolean) 
      Me.EventSource = EventSource 
      Me.Source = Source 
      Me.Description = Description 
      Me.ErrorCode = ErrorCode 
      Me.Cancel = Cancel 
     End Sub 

    End Class 

    Private Delegate Sub PackageOnErrorEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 
    Private Delegate Sub PackageOnFinishEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 
    Private Delegate Sub PackageOnStartEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 
    Private Delegate Sub PackageOnProgressEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 
    Private Delegate Sub PackageOnQueryCancelEventHandler(ByVal sender As Object, ByVal e As DTSEventArgs) 

    Private Class PackageEventsSink 
     Implements DTS.PackageEvents 

     Public Event OnPackageOnError As PackageOnErrorEventHandler 
     Public Event OnPackageOnFinish As PackageOnFinishEventHandler 
     Public Event OnPackageOnStart As PackageOnStartEventHandler 
     Public Event OnPackageOnProgress As PackageOnProgressEventHandler 
     Public Event OnPackageOnQueryCancel As PackageOnQueryCancelEventHandler 

     Overridable Overloads Sub OnError(ByVal EventSource As String, _ 
     ByVal ErrorCode As Integer, ByVal Source As String, _ 
     ByVal Description As String, ByVal HelpFile As String, _ 
     ByVal HelpContext As Integer, ByVal IDofInterfaceWithError As String, _ 
     ByRef pbCancel As Boolean) Implements DTS.PackageEvents.OnError 

      Dim e As New DTSEventArgs(EventSource, Source, Description, ErrorCode, pbCancel) 
      TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnError in {0}; ErrorCode = {1}, Source = {2}, Description = {3}, HelpFile = {4}, HelpContext = {5}, IDofInterfaceWithError = {6}", EventSource, ErrorCode, Source, Description, HelpFile, HelpContext, IDofInterfaceWithError)) 
      RaiseEvent OnPackageOnError(Me, e) 
      pbCancel = e.Cancel 

     End Sub 

     Overridable Overloads Sub OnFinish(ByVal EventSource As String) Implements DTS.PackageEvents.OnFinish 

      Dim e As New DTSEventArgs(EventSource, String.Empty, "Execution Finished", 0, False) 
      TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnFinish in {0}", EventSource)) 
      RaiseEvent OnPackageOnFinish(Me, e) 

     End Sub 

     Overridable Overloads Sub OnProgress(ByVal EventSource As String, _ 
     ByVal ProgressDescription As String, ByVal PercentComplete As Integer, _ 
     ByVal ProgressCountLow As Integer, ByVal ProgressCountHigh As Integer) _ 
     Implements DTS.PackageEvents.OnProgress 

      Dim e As New DTSEventArgs(EventSource, String.Empty, ProgressDescription, 0, False) 
      e.PercentComplete = PercentComplete 
      TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnProgress in {0}; ProgressDescription = {1}, PercentComplete = {2}, ProgressCountLow = {3}, ProgressCountHigh = {4}", EventSource, ProgressDescription, PercentComplete, ProgressCountLow, ProgressCountHigh)) 
      RaiseEvent OnPackageOnProgress(Me, e) 

     End Sub 


     Overridable Overloads Sub OnQueryCancel(ByVal EventSource As String, ByRef pbCancel As Boolean) Implements DTS.PackageEvents.OnQueryCancel 

      Dim e As New DTSEventArgs(EventSource, String.Empty, String.Empty, 0, pbCancel) 
      TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnQueryCancel in {0}; pbCancel = {1}", EventSource, pbCancel)) 
      RaiseEvent OnPackageOnQueryCancel(Me, e) 
      pbCancel = e.Cancel 

     End Sub 

     Overridable Overloads Sub OnStart(ByVal EventSource As String) Implements DTS.PackageEvents.OnStart 

      Dim e As New DTSEventArgs(EventSource, String.Empty, "Execution Started", 0, False) 
      TraceEvent(TraceEventType.Verbose, 0, String.Format(" OnStart in {0}", EventSource)) 
      RaiseEvent OnPackageOnStart(Me, e) 

     End Sub 

    End Class 

     #End Region 

End Class 

End Namespace 
関連する問題