次の方法で共有


エンドポイントの実装

エンドポイントは、要求をネイティブにリッスンできるサービスです。SMO は、Endpoint オブジェクトを使用することで、さまざまな種類のエンドポイントをサポートしています。Endpoint オブジェクトのインスタンスを作成し、そのプロパティを設定することで、特定のプロトコルを必要とする特定の種類のペイロードを処理するためのエンドポイント サービスを作成できます。

Endpoint オブジェクトの EndpointType プロパティを使用して、次の種類のペイロードの 1 つを指定することができます。

  • データベース ミラーリング

  • SOAP

  • Service Broker

  • Transact-SQL

また、ProtocolType プロパティを使用して、サポートされている次の 2 つのプロトコルを指定することができます。

  • HTTP プロトコル

  • TCP プロトコル

ペイロードの種類を指定すると、Payload オブジェクト プロパティを使用して実際のペイロードを設定することができます。Payload オブジェクト プロパティは、プロパティを変更できる、指定された種類のペイロード オブジェクトへの参照を提供します。

DatabaseMirroringPayload オブジェクトに対して、ミラーリング ロール、および暗号化が有効であるかどうかを指定する必要があります。ServiceBrokerPayload オブジェクトには、メッセージ転送、許可される最大接続数、および認証モードに関する情報が必要です。SoapPayloadMethod オブジェクトでは、さまざまなプロパティの設定が必要です。これには、クライアントが使用できる SOAP ペイロード メソッド (ストアド プロシージャおよびユーザー定義関数) を指定する、Add オブジェクト プロパティなどがあります。

Protocol オブジェクト プロパティを使用すると、ProtocolType プロパティで指定された型のプロトコル オブジェクトを参照して、実際のプロトコルを設定することができます。HttpProtocol オブジェクトには、制限された IP アドレス、ポート、Web サイト、および認証情報のリストが必要です。また、TcpProtocol オブジェクトには、制限された IP アドレスおよびポート情報のリストも必要です。

エンドポイントを作成して定義を完了したら、データベース ユーザー、グループ、ロール、およびログオンに対して、アクセスの許可、取り消し、および拒否を行うことができます。

次のコード例では、アプリケーションを作成するプログラミング環境、プログラミング テンプレート、およびプログラミング言語を選択する必要があります。詳細については、「Visual Studio .NET で Visual Basic SMO プロジェクトを作成する方法」および「Visual Studio .NET で Visual C# SMO プロジェクトを作成する方法」を参照してください。

Visual Basic でのデータベース ミラーリング エンドポイント サービスの作成

コード例では、SMO でデータベース ミラーリング エンドポイントを作成する方法を示します。これは、データベース ミラーを作成する前に必要な操作です。Database オブジェクトの IsMirroringEnabled プロパティおよびその他のプロパティを使用して、データベース ミラーを作成します。

'Set up a database mirroring endpoint on the server before setting up a database mirror.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Define an Endpoint object variable for database mirroring.
Dim ep As Endpoint
ep = New Endpoint(srv, "Mirroring_Endpoint")
ep.ProtocolType = ProtocolType.Tcp
ep.EndpointType = EndpointType.DatabaseMirroring
'Specify the protocol ports.
ep.Protocol.Http.SslPort = 5024
ep.Protocol.Tcp.ListenerPort = 6666
'Specify the role of the payload.
ep.Payload.DatabaseMirroring.ServerMirroringRole = ServerMirroringRole.All
'Create the endpoint on the instance of SQL Server.
ep.Create()
'Start the endpoint.
ep.Start()
Console.WriteLine(ep.EndpointState)

Visual C# でのデータベース ミラーリング エンドポイント サービスの作成

コード例では、SMO でデータベース ミラーリング エンドポイントを作成する方法を示します。これは、データベース ミラーを作成する前に必要な操作です。Database オブジェクトの IsMirroringEnabled プロパティおよびその他のプロパティを使用して、データベース ミラーを作成します。

//Set up a database mirroring endpoint on the server before 
//setting up a database mirror. 
//Connect to the local, default instance of SQL Server. 
{ 
   Server srv = default(Server); 
   srv = new Server(); 
   //Define an Endpoint object variable for database mirroring. 
   Endpoint ep = default(Endpoint); 
   ep = new Endpoint(srv, "Mirroring_Endpoint"); 
   ep.ProtocolType = ProtocolType.Tcp; 
   ep.EndpointType = EndpointType.DatabaseMirroring; 
   //Specify the protocol ports. 
   ep.Protocol.Http.SslPort = 5024; 
   ep.Protocol.Tcp.ListenerPort = 6666; 
   //Specify the role of the payload. 
   ep.Payload.DatabaseMirroring.ServerMirroringRole = ServerMirroringRole.All; 
   //Create the endpoint on the instance of SQL Server. 
   ep.Create(); 
   //Start the endpoint. 
   ep.Start(); 
   Console.WriteLine(ep.EndpointState); 
}