ScriptObjectModel.Events 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回 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 来触发错误、警告和信息信息。