상세 컨텐츠

본문 제목

SQL 서버 - DB 테이블의 데이터 변경에 대한 알림 처리

C#

by 탑~! 2011. 11. 17. 17:51

본문


SQL Server Notification Services
; http://en.wikipedia.org/wiki/SQL_Server_Notification_Services


wmi Sql table notification
; http://www.ureader.com/msg/14861679.aspx


Sample: Using the WMI Event Provider with the .NET Framework
; http://msdn.microsoft.com/en-us/library/ms179315.aspx


using System;
using System.Management;

class SQLWEPExample
{
    public static void Main(string[] args)
    {
        string query =  @"SELECT * FROM DDL_EVENTS " ;
        // Default namespace for default instance of SQL Server
        string managementPath =
            @"\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER";
        ManagementEventWatcher  watcher =
            new ManagementEventWatcher(new WqlEventQuery (query));
        ManagementScope scope = new ManagementScope (managementPath);
        scope.Connect();
        watcher.Scope = scope;
        Console.WriteLine("Watching...");
        while (true)
        {
            ManagementBaseObject obj = watcher.WaitForNextEvent();
            Console.WriteLine("Event!");
            foreach (PropertyData data in obj.Properties)
            {
                Console.Write("{0}:", data.Name);
                if (data.Value == null)
                {
                    Console.WriteLine("<null>");
                }
                else
                {
                    Console.WriteLine(data.Value.ToString());
                }
            }
            Console.WriteLine("-----");
            Console.WriteLine();
            Console.WriteLine();
        }
    }
}

'C#' 카테고리의 다른 글

TreeNode 찾기  (0) 2011.12.14
c# InputBox  (0) 2011.12.14
File Transaction  (0) 2011.11.17
EscapeSequence  (0) 2011.11.17
WebClient Download Sample  (0) 2011.11.17

관련글 더보기