共用方式為


ServerConnection Class

The ServerConnection object represents a connection to a server.

命名空間: Microsoft.SqlServer.Management.Common
組件: Microsoft.SqlServer.ConnectionInfo (in microsoft.sqlserver.connectioninfo.dll)

語法

'宣告
Public NotInheritable Class ServerConnection
    Inherits ConnectionManager
public sealed class ServerConnection : ConnectionManager
public ref class ServerConnection sealed : public ConnectionManager
public final class ServerConnection extends ConnectionManager
public final class ServerConnection extends ConnectionManager

備註

更新的文字:

The ServerConnection class is served by the Server class and replication classes such as the ReplicationServer class.

Typically, you don't have to declare an instance of the ServerConnection object because it is created automatically with the Server object. Declare a ServerConnection object variable if you want to store the connection settings for re-use. The ConnectionContext property of the Server object points to a ServerConnection object. The ServerConnection object contains properties that relate to the connection between the Server object and the instance of SQL Server. You can use it to view or modify certain aspects of the connection, such as the process ID, processing transactions, the authentication mode, execution mode, and even to run Transact-SQL commands directly.

By using the ServerConnection object, you can do the following:

  • Run Transact-SQL statements directly over the connection to the instance of SQL Server.

  • Change the connection settings, such as the authentication method.

  • Begin, commit and roll back transactions.

  • Capture the Transact-SQL statements generated by the SMO application.

只有 Microsoft .NET Framework 2.0 版支援此命名空間、類別或成員。

Inheritance Hierarchy

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

範例

For another example of this method with the Database object, see ExecuteNonQuery.

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

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

平台

開發平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

目標平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

請參閱

參考

ServerConnection Members
Microsoft.SqlServer.Management.Common Namespace

其他資源

How to: Connect to the Local Instance of SQL Server by Using Windows Authentication in Visual Basic .NET
Connecting to an Instance of SQL Server