Share via


實作端點

適用於:SQL ServerAzure SQL DatabaseAzure SQL 受控執行個體Azure Synapse Analytics

端點是可原生接聽要求的服務。 SMO 支援 Endpoint 使用 物件的各種端點類型。 您可以建立端點服務,以處理使用特定通訊協定的特定承載類型,方法是建立 物件的實例 Endpoint 並設定其屬性。

EndpointType物件的 屬性 Endpoint 可用來指定下列承載類型:

  • 資料庫鏡像

  • SOAP (支援 SOAP 端點存在於 SQL Server 2008 R2 (10.50.x) 和舊版 SQL Server 中)

  • Service Broker

  • Transact-SQL

此外, ProtocolType 屬性也可以用來指定下列兩個支援的通訊協定:

  • HTTP 通訊協定

  • TCP 通訊協定

指定承載類型之後,可以使用 物件屬性來設定 Payload 實際承載。 Payload物件屬性提供指定型別之承載物件的參考,可以修改屬性。

DatabaseMirroringPayload針對 物件,您必須指定鏡像角色,以及是否啟用加密。 ServiceBrokerPayload物件需要訊息轉送、允許的連線數目上限和驗證模式的相關資訊。 物件 SoapPayloadMethod 需要設定各種屬性,包括 Add 物件屬性,以指定用戶端可用的 SOAP 承載方法(預存程式和使用者定義函式)。

同樣地,可以使用參考 屬性所 ProtocolType 指定型別之通訊協定物件的物件屬性,來設定 Protocol 實際的通訊協定。 HttpProtocol物件需要受限制的 IP 位址清單,以及埠、網站和驗證資訊。 物件 TcpProtocol 也需要受限制的 IP 位址和埠資訊清單。

建立並完整定義端點時,可以授與、撤銷和拒絕資料庫使用者、群組、角色和登入的存取權。

範例

針對下列程式碼範例,您必須選取程式設計環境、程式設計範本和程式設計語言,才能建立您的應用程式。 如需詳細資訊,請參閱 在 Visual Studio .NET 中建立 Visual C# SMO 專案。

在 Visual Basic 中建立資料庫鏡像端點服務

程式碼範例示範如何在 SMO 中建立資料庫鏡像端點。 建立資料庫鏡像之前,這是必要的。 IsMirroringEnabled使用 物件上的 Database 和其他屬性來建立資料庫鏡像。

'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 中建立資料庫鏡像端點。 建立資料庫鏡像之前,這是必要的。 IsMirroringEnabled使用 物件上的 Database 和其他屬性來建立資料庫鏡像。

{  
            //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 = 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);  
        }  

在 PowerShell 中建立資料庫鏡像端點服務

程式碼範例示範如何在 SMO 中建立資料庫鏡像端點。 建立資料庫鏡像之前,這是必要的。 IsMirroringEnabled使用 物件上的 Database 和其他屬性來建立資料庫鏡像。

# Set the path context to the local, default instance of SQL Server.  
CD \sql\localhost\  
$srv = get-item default  
  
#Get a new endpoint to congure and add  
$ep = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Endpoint -argumentlist $srv,"Mirroring_Endpoint"  
  
#Set some properties  
$ep.ProtocolType = [Microsoft.SqlServer.Management.SMO.ProtocolType]::Tcp  
$ep.EndpointType = [Microsoft.SqlServer.Management.SMO.EndpointType]::DatabaseMirroring  
$ep.Protocol.Http.SslPort = 5024  
$ep.Protocol.Tcp.ListenerPort = 6666 #inline comment  
$ep.Payload.DatabaseMirroring.ServerMirroringRole = [Microsoft.SqlServer.Management.SMO.ServerMirroringRole]::All  
  
# Create the endpoint on the instance  
$ep.Create()  
  
# Start the endpoint  
$ep.Start()  
  
# Report its state  
$ep.EndpointState;  

另請參閱

資料庫鏡像端點 (SQL Server)