Share via


Construtor ServerConnection (SqlConnection)

Inicializa uma nova instância da classe ServerConnection com os parâmetros de conexão especificados.

Namespace:  Microsoft.SqlServer.Management.Common
Assembly:  Microsoft.SqlServer.ConnectionInfo (em Microsoft.SqlServer.ConnectionInfo.dll)

Sintaxe

'Declaração
Public Sub New ( _
    sqlConnection As SqlConnection _
)
'Uso
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
)

Parâmetros

  • sqlConnection
    Tipo: SqlConnection
    Um objeto do sistema SqlConnection que especifica os parâmetros de conexão associados à conexão referenciada.

Exemplos

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

Consulte também

Referência

ServerConnection Classe

Sobrecarregado ServerConnection

Namespace Microsoft.SqlServer.Management.Common

Outros recursos

Conectando-se a uma instância do SQL Server