Joe Webb Blog

Musing and observations about SQL Server, other technogies, and sometimes just life in general

Using the SSNS Management.NMO NameSpace

One the more welcomed enhancements of SQL Server 2005 Notification Services was the new Microsoft.SqlServer.Management.Nmo namespace. The namespace provides classes that may be used develop and administer SSNS instances and applications.

For example, the following C# console application may be used to iterate through each SSNS instance of a SQL Server 2005 instance, printing its name to the console window. If you'd like to try this code for yourself, don't forget to add a reference to the microsoft.sqlserver.smo.dll in your Visual Studio 2005 project.

 

using System;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Smo;
 
 
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //SQL Server instance 
            string myServer = @"CEDAR\SS2005";
            Server server = new Server(myServer);
 
            //Notification Services object
            NotificationServices ns = server.NotificationServices;
 
            //enumerate through each instances
            for (int cnt = 0; cnt < ns.Instances.Count; cnt++)
            {   
                string nam = ns.Instances[cnt].Name;
                Console.WriteLine(nam);
            }
 
            //pause to view the output
            Console.WriteLine("Press the Enter key to continue");
            Console.Read();
        }
    }
}

Although the quickest way to create a SSNS instance and application is still to craft an XML-based Instance Configuration File (ICF) and Application Definition File (ADF), it's nice to have the nmo namespace available to automate some tasks as needed.

Cheers!

Joe

kick it on DotNetKicks.com