SSIS Package运行状态

            为了在运行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中添加判断条件。

转载于:https://www.cnblogs.com/cooperyin/archive/2009/07/21/1527854.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值