Notification Services—Enumerating a Notification Services Instance Database


Jump to: navigation, search
CSharp-Online.NET:Articles
Database Articles

Notification Services

© 2006 O'Reilly Media, Inc.

Enumerating a Notification Services Instance Database

This example enumerates the filegroup, database files, and logfiles for the StockWatch Notification Services instance created in Example 18-1:

using System;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
 
class Program
{
  static void Main(string[] args)
  {
  Server server = new Server("(local)");
  NotificationServices ns = 
    server.NotificationServices;
  Instance ins = 
    ns.Instances["StockWatch"];
  InstanceDatabaseOptions ido = 
    ins.InstanceDatabaseOptions;
  Console.WriteLine("INSTANCE DATABASE OPTIONS:");
  Console.WriteLine(" Name: " + ido.Name);
  Console.WriteLine(" DefaultFileGroup: " + 
    ido.DefaultFileGroup);
  Console.WriteLine(Environment.NewLine + 
    "FILE GROUPS:");
  foreach (InstanceDatabaseFileGroup idfg in 
    ido.InstanceDatabaseFileGroups)
  {
    Console.WriteLine(" Name: " + idfg.Name);
    Console.WriteLine(Environment.NewLine + "DATABASE FILES");
    foreach (InstanceDatabaseFile idf in idfg.InstanceDatabaseFiles)
    Console.WriteLine(" Name: " + idf.Name);
  }
  Console.WriteLine(Environment.NewLine + "LOG FILES:");
  foreach (InstanceDatabaseLogFile idlf in ido.InstanceDatabaseLogFiles)
  Console.WriteLine(" Name: " + idlf.Name);
  Console.WriteLine(Environment.NewLine + "Press any key to continue.");
  Console.ReadKey( );
  }
}

Results are shown in Figure 18-9.

Each Notification Services instance has one database that can optionally contain one or more filegroups. If you define filegroups, one must be called PRIMARY. Use SQL Server Management Studio if you need to alter the Notification Services instance database after creating the instance.

Image:ProgSQLServer2005fig18-9.jpg
Figure 18-9. Results for enumerating a Notification Services instance database example

The NMO classes for managing the instance database, filegroups, files, and logfiles are described in Table 18-13.

Table 18-13. NMO classes for managing instance databases

Instance Description
InstanceDatabaseFile Represents an instance database file.
InstanceDatabaseFileCollection Represents a collection of instance databases as

InstanceDatabase objects. The InstanceDatabaseFiles property of the InstanceDatabaseFileGroup class returns the instance databases in the instance database filegroup.

InstanceDatabaseFileGroup Represents an application database filegroup.
InstanceDatabaseFileGroupCollection Represents a collection of instance database filegroups as

InstanceDatabaseFileGroup objects. The InstanceDatabaseFileGroups property of the InstanceDatabaseOptions class returns the instance database filegroups in the application.

InstanceDatabaseLogFile Represents an instance database logfile.
InstanceDatabaseLogFileCollection Represents a collection of instance database logfiles as InstanceDatabaseLogFile objects. The InstanceDatabaseLogFiles property of the InstanceDatabaseOptions class

returns the instance database logfiles in the application.

InstanceDatabaseOptions Represents database options for the instance database. The

InstanceDatabaseOptions property of the Instance class returns the database properties for the instance.


Previous_Page_.gif Next_Page_.gif


Personal tools