Share via


Notification Services 엔진 호스팅

Notification Services 2.0에서는 Notification Services 인스턴스마다 호스팅된 이벤트 공급자, 생성자 또는 배포자가 실행되는 각 서버에 Windows 서비스를 설치해야 했습니다. 뿐만 아니라 알림 응용 프로그램을 재배포하려는 개발자는 배포에 하나 이상의 Windows 서비스를 추가하고 관리를 위해 서비스를 하나 더 만들었습니다.

SQL Server 2005에서는 자체의 응용 프로그램이나 프로세스 내에서 Notification Services 엔진을 호스팅할 수 있습니다. 엔진을 호스팅할 경우에는 엔진 구성 요소를 실행하기 위해 NS$instanceName Windows 서비스를 설치하지 않아도 됩니다. 따라서 응용 프로그램에 Notification Services 솔루션을 간단히 포함시킬 수 있습니다.

Notification Services 엔진 호스팅

Notification Services는 Notification Services 엔진 호스팅을 위한 아주 간단한 API를 제공합니다. 따라서 NSInstance 클래스를 인스턴스화하고 호스팅하려는 인스턴스의 이름을 제공하기만 하면 됩니다. 그런 후 StartInstance 메서드를 호출하여 엔진을 시작합니다. 엔진을 중지하려면 StopInstance 메서드를 호출합니다. 다음 예에서는 엔진을 중지 및 시작하는 데 필요한 코드를 보여 줍니다.

try
{
    // Instantiate the Notification Services instance.
    NSInstance nsInstance = new NSInstance("FlightInstance");

    // Start the instance.
    Console.WriteLine("Starting instance...");
    nsInstance.StartInstance();

    // Check the IsRunning property to verify that 
    // this process is running the instance.
    if (nsInstance.IsRunning == true)
        Console.WriteLine("The instance is running.");
    else
        Console.WriteLine("The instance is NOT running!");

    // Stop instance.
    Console.WriteLine("Stopping instance...");
    nsInstance.StopInstance();

}
catch (Exception ex)
{
    // Write exception message to the console.
    Console.WriteLine(ex.Message);
}

오류 처리

인스턴스가 실행되고 있는 동안 런타임 오류가 발생할 수 있습니다. 이러한 오류는 Error 이벤트가 트리거될 때 호출되는 ErrorEventHandler 대리자를 통해 호스팅 프로세스로 다시 보고됩니다. 이 이벤트가 발생하면 호스트에게 알리도록 대리자에게 요구되며 인스턴스는 중지됩니다.

다음 예에서는 이 이벤트에 응답하는 방법을 보여 줍니다.

// Define an error handler for the hosted execution engine.
private void InstanceErrorHandler(object sender, ErrorEventArgs e)
{
    Console.WriteLine (e.GetException ().ToString ());
}

// Start and stop the hosted execution engine.
public void ErrorHandlingStartStop()
{
    try
    {
        // Instantiate the Notification Services instance.
        NSInstance nsInstance = new NSInstance("FlightInstance");

        // Add an error handler to the instance.
        nsInstance.Error += 
            new NSInstance.ErrorEventHandler(InstanceErrorHandler);

        // Start the instance.
        Console.WriteLine("Starting instance...");
        nsInstance.StartInstance();

        // Check the IsRunning property to verify that 
        // this process is running the instance.
        if (nsInstance.IsRunning == true)
            Console.WriteLine("The instance is running.");
        else
            Console.WriteLine("The instance is NOT running!");


        // Stop the instance.
        Console.WriteLine("Stopping instance...");
        nsInstance.StopInstance();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

송신자는 NSInstance 개체입니다.

Notification Services 인스턴스 실행

호스팅된 이벤트 공급자, 생성자 및 배포자를 실행하는 엔진을 로컬 컴퓨터에서 실행하려면 다음을 수행해야 합니다.

  • 호스팅된 이벤트 공급자, 생성자 또는 배포자가 실행되는 각 서버에 Notification Services 엔진 구성 요소를 설치해야 합니다.
  • 이러한 각 서버에서 인스턴스를 등록해야 합니다. 인스턴스를 등록할 때 Windows 서비스를 만들 필요는 없습니다. 호스팅된 엔진이 Windows 서비스를 대신할 수 있기 때문입니다.
  • 이러한 각 서버에 응용 프로그램을 설치해야 합니다.
  • 이러한 각 서버에서 인스턴스를 인스턴스화하고 시작하는 코드를 호출해야 합니다.

Windows 서비스를 설치할 경우에는 Windows를 서비스를 시작한 다음 응용 프로그램에서 해당 인스턴스를 동시에 시작할 수 없다는 사실에 유의하십시오. 언제든지 한 프로세스의 스레드 하나만 인스턴스를 "소유"할 수 있습니다.

NS$instanceName Windows 서비스를 시작한 후 응용 프로그램에서 해당 인스턴스를 시작하려고 하면 Notification Services는 예외를 발생시키고 응용 프로그램은 인스턴스를 시작하지 않습니다. 그 반대의 경우도 마찬가지입니다. 응용 프로그램이 인스턴스를 실행하고 있을 때 Windows 서비스를 시작하려고 하면 Windows 서비스가 시작되지 못합니다.

해당 서버에서 인스턴스의 엔진을 소유하는 스레드에 오류가 발생하면 해당 프로세스 내의 다른 스레드가 인스턴스의 소유권을 인계 받을 수 있습니다.

[!참고] 엔진을 호스팅할 경우에는 SQL Server Management Studio, net 명령 및 제어판의 서비스와 같이 인스턴스를 시작 및 중지하는 데 사용하는 표준 도구를 사용하여 인스턴스를 시작 및 중지할 수 없습니다.

보안 요구 사항

응용 프로그램이나 프로세스는 호스팅된 이벤트 공급자, 생성자 및 배포자의 작동을 제어하므로 관련 작업을 수행하는 데 필요한 Windows 및 데이터베이스 사용 권한이 있어야 합니다. 이러한 권한에는 SQLServer2005NotificationServicesUser$ComputerName Windows 그룹의 멤버 자격 및 해당 Notification Services 데이터베이스 역할의 멤버 자격이 포함됩니다. Notification Services 인스턴스 실행에 필요한 사용 권한에 대한 자세한 내용은 Notification Services 인스턴스에 대한 Windows 계정 구성Notification Services 인스턴스에 대한 SQL Server 사용 권한 구성을 참조하십시오.

Notification Services 구성 요소 포함

응용 프로그램에 Notification Services를 포함시킬 경우 다음 어셈블리를 포함시켜야 합니다.

  • Microsoft.SqlServer.NotificationServices.dll
  • Microsoft.SqlServer.Smo.dll
  • nscontrol.exe

SQL Server 2005 구성 요소의 재배포에 대해서는 SQL Server 2005 사용권 계약을 참조하십시오.

참고 항목

개념

Notification Services에 대한 보안 고려 사항
Notification Services 인스턴스에 대한 Windows 계정 구성
Notification Services 인스턴스에 대한 SQL Server 사용 권한 구성

관련 자료

Notification Services 배포

도움말 및 정보

SQL Server 2005 지원 받기