ConnectionContext 属性

获取 SQL Server 实例的当前服务器连接详细信息。

命名空间:  Microsoft.SqlServer.Management.Smo
程序集:  Microsoft.SqlServer.Smo(在 Microsoft.SqlServer.Smo.dll 中)

语法

声明
Public ReadOnly Property ConnectionContext As ServerConnection
    Get
用法
Dim instance As Server
Dim value As ServerConnection

value = instance.ConnectionContext
public ServerConnection ConnectionContext { get; }
public:
virtual property ServerConnection^ ConnectionContext {
    ServerConnection^ get () sealed;
}
abstract ConnectionContext : ServerConnection
override ConnectionContext : ServerConnection
final function get ConnectionContext () : ServerConnection

属性值

类型:Microsoft.SqlServer.Management.Common. . :: . .ServerConnection
一个 ServerConnection 对象,该对象指定与 SQL Server 实例的当前连接的详细信息。

实现

IAlienRoot. . :: . .ConnectionContext

注释

This property can be used to change connection settings, such as the name of the instance of SQL Server or the authentication type. The ConnectionContext property is represented by the ServerConnection class. When connecting to the local instance of SQL Server by using Windows Authentication, the default values are used. You do not have to set any properties.

示例

C#

Server srv = new Server("(local)");
ServerConnection conContext = new ServerConnection();
conContext = srv.ConnectionContext;
conContext.LoginSecure = false;
conContext.Login = vlogin;
conContext.Password = vpassword;
Server srv2 = new Server(conContext);

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$conContext = $srv.ConnectionContext
$conContext.LoginSecure = $FALSE
$conContext.Login = vlogin
$conContext.Password = vpassword
$srv2 = new-object Microsoft.SqlServer.Management.Smo.Server($conContext)