Podnoszenie zdarzeń w zadania skryptu
Zdarzenia umożliwiają raportowanie błędów, ostrzeżeń i inne informacje, takie jak postęp zadania lub stan pakiet zawierającego.Pakiet zawiera zdarzenie obsługę zarządzania zdarzenie powiadomienia.Zadania skryptu można podnieść zdarzenia przez wywołanie metody na Events Właściwość Dts obiektu.Aby uzyskać więcej informacji dotyczących sposobu Integration Services zdarzenia uchwyt pakietów, zobacz Obsługa zdarzeń usług integracji.
Zdarzenia mogą być rejestrowane żadnego dostawca dziennika, który jest włączony w pakiet.Włączeni przechowywać informacje o zdarzeniach w magazynie danych.Można także użyć zadania skryptu Log metoda rejestrować informacje do dostawca dziennika bez podnoszenia zdarzeń.Aby uzyskać więcej informacji na temat używania Log metoda, zobacz Zadania skryptu logowania.
Aby wygenerować zdarzenie, zadania skryptu wywołuje jedną z metod udostępnianych przez Events właściwość.W poniższej tabela wymieniono metody udostępniane przez Events właściwość.
Zdarzenie |
Opis |
---|---|
[ M:Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents.FireCustomEvent(System.String,System.String,System.Object[]@,System.String,System.Boolean@) ] |
Podnosi użytkownika niestandardowego zdarzenie w pakiet. |
[ M:Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents.FireError(System.Int32,System.String,System.String,System.String,System.Int32) ] |
Informuje pakiet warunek błędu. |
[ M:Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents.FireInformation(System.Int32,System.String,System.String,System.String,System.Int32,System.Boolean@) ] |
Zawiera informacje dla użytkownika. |
[ M:Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents.FireProgress(System.String,System.Int32,System.Int32,System.Int32,System.String,System.Boolean@) ] |
Informuje pakiet postęp zadania. |
[ M:Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents.FireQueryCancel ] |
Zwraca wartość, która wskazuje, czy pakiet potrzebuje zadań do zamknięcia niedziałający przedwcześnie. |
[ M:Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents.FireWarning(System.Int32,System.String,System.String,System.String,System.Int32) ] |
Informuje pakiet zadanie jest w stanie uzasadnia użytkownika powiadomienie, ale nie jest błąd. |
Przykład zdarzenia
Poniższy przykład ilustruje sposób podnieść zdarzenia w ramach zadania skryptu.W przykładzie użyto macierzystych funkcja interfejsu API systemu Windows, czy dostępne jest połączenie z Internetem.Jeśli połączenie nie jest dostępny, zgłasza błąd.Jeśli połączenie modemowe potencjalnie nietrwała jest używany, przykład podnosi ostrzeżenie.W przeciwnym wypadku zwraca komunikat informacyjny wykryto połączenia internetowego.
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
Dim fireAgain as Boolean
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, fireAgain)
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
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class ScriptMain
{
[DllImport("wininet")]
private extern static long InternetGetConnectedState(ref long dwFlags, long dwReserved);
private enum ConnectedStates
{
LAN = 0x2,
Modem = 0x1,
Proxy = 0x4,
Offline = 0x20,
Configured = 0x40,
RasInstalled = 0x10
};
public void Main()
{
//
long dwFlags = 0;
long connectedState;
bool fireAgain = true;
int state;
connectedState = InternetGetConnectedState(ref dwFlags, 0);
state = (int)ConnectedStates.Modem;
if (connectedState != 0)
{
if ((dwFlags & state) == state)
{
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, ref fireAgain);
}
}
else
{
// If not connected to the Internet, raise an error.
Dts.Events.FireError(0, "Script Task Example", "Internet connection not available.", String.Empty, 0);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
|
Zobacz także