共用方式為


Server.ConnectionContext 屬性

Gets the current server connection details for the instance of 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
A ServerConnection object that specifies the details of the current connection to the instance of 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)

請參閱

參考

Server 類別

Microsoft.SqlServer.Management.Smo 命名空間

其他資源

連接到 SQL Server 的執行個體

從 SQL Server 的執行個體中斷連接

管理伺服器