Handling SMO Events
There are server event types that can be subscribed to by using an event handler and the ServerConnection object.
Many of the instance classes in SQL Server Management Objects (SMO) can trigger events when certain actions on the server occur.
These events can be handled programmatically by setting up an event handler and subscribing to the associated events. This type of event handling is transient because all the subscriptions are removed when the SMO client program exits.
ConnectionContext Event Handling
The ServerConnection object supports several event types. The event property must be set to an instance of an appropriate event handler, and the event handler object must be defined as a protected function that handles the event.
Event Subscription
You handle events by writing an event handler class, creating an instance of it, assigning the event handler to the parent object, and then subscribing to the event.
An event handler class must be written to handle events. The event handler class can contain more than one event handler function, and must be installed for the events to be handled. The event handler functions receive information about the event from the ServerEventNotificatificationArgs parameter that can be used to report information about the event.
請參閱
工作
How to: Register Event Handlers and Subscribe to Event Handling in Visual Basic .NET