Share via


ServerConnection クラス

ServerConnection オブジェクトは、サーバーへの接続を表します。

名前空間:  Microsoft.SqlServer.Management.Common
アセンブリ:  Microsoft.SqlServer.ConnectionInfo (Microsoft.SqlServer.ConnectionInfo.dll)

構文

'宣言
Public NotInheritable Class ServerConnection _
    Inherits ConnectionManager _
    Implements ISfcConnection
'使用
Dim instance As ServerConnection
public sealed class ServerConnection : ConnectionManager, 
    ISfcConnection
public ref class ServerConnection sealed : public ConnectionManager, 
    ISfcConnection
[<SealedAttribute>]
type ServerConnection =  
    class
        inherit ConnectionManager
        interface ISfcConnection
    end
public final class ServerConnection extends ConnectionManager implements ISfcConnection

説明

ServerConnection クラスは、Server クラス、および ReplicationServer クラスなどのレプリケーション クラスによって処理されます。

ServerConnection オブジェクトのインスタンスは通常、サーバー オブジェクトを使用して自動的に作成されるので、宣言する必要はありません。接続設定を再利用できるように保存する場合は、ServerConnection オブジェクト変数を宣言します。サーバー オブジェクトの ConnectionContext プロパティは、ServerConnection オブジェクトを指します。ServerConnection オブジェクトには、サーバー オブジェクトと SQL Server のインスタンス間の接続に関連するプロパティが含まれています。プロセス ID、処理中のトランザクション、認証モード、実行モードなどの特定の接続設定を表示または変更したり、Transact-SQL コマンドを直接実行したりするために使用できます。

ServerConnection オブジェクトを使用すると、次のような操作を実行できます。

  • SQL Server のインスタンスへの接続に対して Transact-SQL ステートメントを直接実行する。

  • 認証方法などの接続設定を変更する。

  • トランザクションを開始し、コミットしてロールバックする。

  • SMO アプリケーションによって生成された Transact-SQL ステートメントをキャプチャする。

使用例

Database オブジェクトを使用したこのメソッドの他の例については、「[M:Microsoft.SqlServer.Management.Smo.Database.ExecuteNonQuery(System.String]」を参照してください。

'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.

継承階層

System. . :: . .Object
  Microsoft.SqlServer.Management.Common. . :: . .ConnectionSettings
    Microsoft.SqlServer.Management.Common. . :: . .ConnectionManager
      Microsoft.SqlServer.Management.Common..::..ServerConnection

スレッド セーフ

この型の public static (Visual Basic では Shared) のメンバーはすべて、スレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。