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
请参阅
参考
Microsoft.SqlServer.Management.Common 命名空间