I have done some searching for a simple, clear example of how to capture all messages when running a query against Microsoft SQL Server using the SQL Management Objects (SMO).
I haven't been at all happy with what I've found, so I thought I would post the following example, hopefully as a clear and concise code example
A few notes:
1 - "Messages" is a text TextBox that I am using, as you might guess, to write messages to
2 - Note the "AddressOf" in the AddHandler method call. This registers the method so that messages can be passed to the application and handled.
3- I had to define MigDBServer as
Private MigDBServer As Microsoft.SqlServer.Management.Smo.Server
Click Image to view larger Version: