語言

ScriptObjectModel.Events 屬性

定義

回傳 IDTSComponentEvents 包含腳本任務的套件中定義的既有事件集合。

public:
 property Microsoft::SqlServer::Dts::Tasks::ScriptTask::EventsObjectWrapper ^ Events { Microsoft::SqlServer::Dts::Tasks::ScriptTask::EventsObjectWrapper ^ get(); };
public Microsoft.SqlServer.Dts.Tasks.ScriptTask.EventsObjectWrapper Events { get; }
member this.Events : Microsoft.SqlServer.Dts.Tasks.ScriptTask.EventsObjectWrapper
Public ReadOnly Property Events As EventsObjectWrapper

屬性值

包含 IDTSComponentEvents 腳本任務的套件中定義的現有事件集合。

範例

以下用於腳本任務的程式碼範例示範如何從腳本任務中引發事件。 範例使用原生 Windows API 函式來判斷是否有網際網路連線。 若無連線可用,則會報錯。 如果正在使用可能不穩定的數據機連線,範例會發出警告。 否則,會回傳一個資訊訊息,表示已偵測到網際網路連線。

Private Declare Function InternetGetConnectedState Lib "wininet" _  
    (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long  

Private Enum ConnectedStates  
    LAN = &H2  
    Modem = &H1  
    Proxy = &H4  
    Offline = &H20  
    Configured = &H40  
    RasInstalled = &H10  
End Enum  

Public Sub Main()  

    Dim dwFlags As Long  
    Dim connectedState As Long  

    connectedState = InternetGetConnectedState(dwFlags, 0)  

    If connectedState <> 0 Then  
        If (dwFlags And ConnectedStates.Modem) = ConnectedStates.Modem Then  
            Dts.Events.FireWarning(0, "Script Task Example", _  
                "Volatile Internet connection detected.", String.Empty, 0)  
        Else  
            Dts.Events.FireInformation(0, "Script Task Example", _  
                "Internet connection detected.", String.Empty, 0, False)  
        End If  
    Else  
        ' If not connected to the Internet, raise an error.  
        Dts.Events.FireError(0, "Script Task Example", _  
            "Internet connection not available.", String.Empty, 0)  
    End If  

    Dts.TaskResult = ScriptResults.Success  

End Sub  

備註

在腳本任務程式碼中使用 Events 物件 Dts 的屬性來觸發錯誤、警告及資訊訊息。

適用於