Showing posts with label Get Messages From Query Execution. Show all posts
Showing posts with label Get Messages From Query Execution. Show all posts

Friday, November 27, 2015

Capturing Messages, using SMO in VB.NET

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

VB.NET
SMO

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
4 - It is also necessary to add a reference to the ddl that contains the Microsoft SMO extensions.

Add Reference by going to Project-> Add References.
Then choose Assemblies->Extensions, and select Microsoft.SqlServer.Smo



Code:
Click Image to view larger Version:




Capturing Messages, using SMO in VB.NET

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

VB.NET
SMO

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:


Get Restart log using PowerShell

I'm often curious about a restart on a Windows server system. An easy way to get a list of the restart and what initiated it is to use t...