为了在运行SSIS包的过程中,不发生运行冲突,因此在包的设计中加入如下程序判断包的运行状态。当检测过程发现当前服务器正在运行该包,即停止对包的启动。这种技术可以运用于实时的捕捉最新数据,设置Schedule等等。
--VB .Net

Imports System
Imports System.Math
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Public Class ScriptMain
    Public Sub Main()
        Dim jobname As String
        jobname = CStr(Dts.Variables("System::PackageName").Value)

        Dim ssisApplication As Application
        Dim pkgCollection As RunningPackages

        Dim Running As Integer
        Running = 0
        Try
            ssisApplication = New Application
            pkgCollection = ssisApplication.GetRunningPackages("localhost")

            For Each package As RunningPackage In pkgCollection
                If package.PackageName = jobname Then
                    Running = Running + 1
                    If Running > 1 Then Exit For
                End If
            Next
        Catch ex As Exception
            Running = 10
        End Try

        Dts.Variables("IsRunning").Value = Running
        Dts.TaskResult = Dts.Results.Success
    End Sub

End Class

            包的运行状态变量为IsRunning,可在随后的SSIS中添加判断条件。

posted on 2009-07-21 15:44  IvanYin  阅读(337)  评论(0编辑  收藏  举报