共用方式為


ServerConnection 建構函式 (SqlConnection)

使用指定的連接參數,初始化 ServerConnection 類別的新執行個體。

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

語法

'宣告
Public Sub New ( _
    sqlConnection As SqlConnection _
)
'用途
Dim sqlConnection As SqlConnection 

Dim instance As New ServerConnection(sqlConnection)
public ServerConnection(
    SqlConnection sqlConnection
)
public:
ServerConnection(
    SqlConnection^ sqlConnection
)
new : 
        sqlConnection:SqlConnection -> ServerConnection
public function ServerConnection(
    sqlConnection : SqlConnection
)

參數

  • sqlConnection
    型別:SqlConnection
    SqlConnection 系統物件,指定與參考的連接相關聯的連接參數。

範例

C#

String connectionString = "Data Source=(local);Initial Catalog=AdventureWorks2012;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(connectionString);
ServerConnection conn = new ServerConnection(sqlConnection);
Server srv = new Server(conn);
Console.WriteLine(srv.Information.Version);

PowerShell

$connectionString = "Data Source=(local);Initial Catalog=AdventureWorks2012;Integrated Security=SSPI;"
$sqlConnection = new-object System.Data.SqlClient.SqlConnection($connectionString)
$conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection($sqlConnection)
#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 的執行個體