终结点是可以本机侦听请求的服务。 SMO 使用 Endpoint 对象支持各种类型的终结点。 可以通过创建对象的实例 Endpoint 并设置其属性,创建一个终结点服务来处理特定类型的有效负载(该有效负载使用特定协议)。
EndpointType对象的属性Endpoint可用于指定以下有效负载类型:
数据库镜像
SOAP (SQL Server 2008 R2 和早期 SQL Server 版本中提供对 SOAP 终结点的支持)
服务代理商
Transact-SQL
此外, ProtocolType 该属性还可用于指定以下两种受支持的协议:
HTTP 协议
TCP 协议
指定有效负载的类型后,可以使用对象属性设置 Payload 实际有效负载。 对象 Payload 属性提供对指定类型的有效负载对象的引用,可以修改其属性。
DatabaseMirroringPayload对于对象,必须指定镜像角色以及是否启用加密。 该 ServiceBrokerPayload 对象需要有关消息转发、允许的最大连接数和身份验证模式的信息。 对象 SoapPayloadMethod 需要设置各种属性,包括 Add 指定客户端可用的 SOAP 有效负载方法的对象属性(存储过程和用户定义的函数)。
同样,可以使用引用由属性指定的ProtocolType类型的协议对象的对象属性来设置Protocol实际协议。 该 HttpProtocol 对象需要受限 IP 地址、端口、网站和身份验证信息的列表。 该 TcpProtocol 对象还需要一个受限 IP 地址和端口信息列表。
创建并完全定义终结点后,可以向数据库用户、组、角色和登录授予、撤消和拒绝访问权限。
示例:
对于以下代码示例,必须选择编程环境、编程模板和编程语言来创建应用程序。 有关详细信息,请参阅 在 Visual Studio .NET 中创建 Visual Basic SMO 项目 ,并在 Visual Studio .NET 中创建 Visual C# SMO 项目。
在 Visual Basic 中创建数据库镜像终结点服务
该代码示例演示如何在 SMO 中创建数据库镜像终结点。 在创建数据库镜像之前,这是必需的。 IsMirroringEnabled使用对象上的Database属性和其他属性创建数据库镜像。
在 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;