共用方式為


ServerConnection 建構函式

初始化 ServerConnection 類別的新執行個體。

命名空間:  Microsoft.SqlServer.Management.Common
組件:  Microsoft.SqlServer.ConnectionInfo (在 Microsoft.SqlServer.ConnectionInfo.dll 中)

語法

'宣告
Public Sub New
'用途
Dim instance As New ServerConnection()
public ServerConnection()
public:
ServerConnection()
new : unit -> ServerConnection
public function ServerConnection()

備註

此建構函式是由衍生類別建構函式呼叫初始化該類型的狀態。

範例

VB

'Declare a ServerConnection object variable to specify SQL authentication, login and password.
Dim conn As New ServerConnection
conn.LoginSecure = False
conn.Login = vlogin
conn.Password = vpassword
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server(conn)
'The actual connection is made when a property is retrieved.
Console.WriteLine(srv.Information.Version)
'The connection is automatically disconnected when the Server variable goes out of scope.

PowerShell

$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection
$conn.LoginSecure = $FALSE
$conn.Login = vlogin
$conn.Password = vpassword
#Connect to the local, default instance of SQL Server
$srv = new-object Microsoft.SqlServer.Management.Smo.Server($conn)
Write-Host $srv.Information.Version

請參閱

參考

ServerConnection 類別

ServerConnection 多載

Microsoft.SqlServer.Management.Common 命名空間

其他資源

連接到 SQL Server 的執行個體