Server Server Server Constructors

Definition

Overloads

Server() Server() Server()

Initializes a new instance of the Server class.

Server(ServerConnection) Server(ServerConnection)

Initializes a new instance of the Server class based on the specified connection.

Server(String) Server(String) Server(String)

Initializes a new instance of the Server class with the specified name.

Server() Server() Server()

Initializes a new instance of the Server class.

public:
 Server();
public Server ();
Public Sub New ()

Examples

Visual Basic

Powershell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
Write-Host $srv.Information.Version  

Remarks

The default constructor initializes any fields to their default values.

Server(ServerConnection) Server(ServerConnection)

Initializes a new instance of the Server class based on the specified connection.

public:
 Server(Microsoft::SqlServer::Management::Common::ServerConnection ^ serverConnection);
public Server (Microsoft.SqlServer.Management.Common.ServerConnection serverConnection);
Parameters
serverConnection
Microsoft.SqlServer.Management.Common.ServerConnection Microsoft.SqlServer.Management.Common.ServerConnection Microsoft.SqlServer.Management.Common.ServerConnection

A Microsoft.SqlServer.Management.Common.ServerConnection object value that specifies the connection to the instance of SQL Server.

Examples

Visual Basic

PowerShell

#Connect to the local, default instance of SQL Server.  
$srv1 = new-object Microsoft.SqlServer.Management.Smo.Server  
#Modify the default database and the timeout period for the connection.  
$srv1.ConnectionContext.DatabaseName = "AdventureWorks2012"  
$srv1.ConnectionContext.ConnectTimeout = 30  
#Make a second connection using a copy of the ConnectionContext property and verify settings.  
$srv2 = new-object Microsoft.SqlServer.Management.Smo.Server($srv1.ConnectionContext.Copy)  
Write-Host $srv2.ConnectionContext.ConnectTimeout.ToString()  

Server(String) Server(String) Server(String)

Initializes a new instance of the Server class with the specified name.

public:
 Server(System::String ^ name);
public Server (string name);
Public Sub New (name As String)
Parameters
name
String String String

A String value that specifies the name of the instance of SQL Server.

Examples

Visual Basic

PowerShell

#the strServer string variable contains the name of a remote instance of SQL Server.  
$srv = new-object Microsoft.SqlServer.Management.Smo.Server($strServer)  
#The actual connection is made when a property is retrieved.  
Write-Host $srv.Information.Version  

Remarks

Use this constructor when the required instance of SQL Server is not the local, default instance. You can use this method when the SQL Server instance is local, but is not the default installation. You can also use this method for remote instances of SQL Server.

Applies to