The object represents a connection to a server.
Assembly: Microsoft.SqlServer.ConnectionInfo (in Microsoft.SqlServer.ConnectionInfo.dll)
Typically, you don't have to declare an instance of the object because it is created automatically with the Server object. Declare a 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 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 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.
For another example of this method with the Database object, see .
'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.