ServerConnection ServerConnection ServerConnection Class

Definition

public sealed class ServerConnection : Microsoft.SqlServer.Management.Common.ConnectionManager, Microsoft.SqlServer.Management.Common.ISfcConnection
type ServerConnection = class
    inherit ConnectionManager
    interface ISfcConnection
Public NotInheritable Class ServerConnection
Inherits ConnectionManager
Implements ISfcConnection
Inheritance
Implements

Constructors

ServerConnection() ServerConnection() ServerConnection()
ServerConnection(IRenewableToken) ServerConnection(IRenewableToken) ServerConnection(IRenewableToken)

Creates a ServerConnection object taking in the token. The extra boolean is used to overload this constructor as another constructor with string is present.

ServerConnection(SqlConnection) ServerConnection(SqlConnection) ServerConnection(SqlConnection)

Constructs a new ServerConnection object from the given SqlConnection

ServerConnection(SqlConnection, IRenewableToken) ServerConnection(SqlConnection, IRenewableToken) ServerConnection(SqlConnection, IRenewableToken)

Constructs a new ServerConnection object

ServerConnection(SqlConnectionInfo) ServerConnection(SqlConnectionInfo) ServerConnection(SqlConnectionInfo)
ServerConnection(String) ServerConnection(String) ServerConnection(String)
ServerConnection(String, Boolean) ServerConnection(String, Boolean) ServerConnection(String, Boolean)
ServerConnection(String, String, SecureString) ServerConnection(String, String, SecureString) ServerConnection(String, String, SecureString)
ServerConnection(String, String, String) ServerConnection(String, String, String) ServerConnection(String, String, String)

Properties

AccessToken AccessToken AccessToken Inherited from ConnectionSettings
ApplicationIntent ApplicationIntent ApplicationIntent

The application intent of the connection

(Inherited from ConnectionSettings)
ApplicationName ApplicationName ApplicationName

The name of the application. 'SQL Management' if no application name has been provided. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
Authentication Authentication Authentication

The authentication type of the connection

(Inherited from ConnectionSettings)
AutoDisconnectMode AutoDisconnectMode AutoDisconnectMode Inherited from ConnectionManager
BatchSeparator BatchSeparator BatchSeparator

Defines the batch separator used by the ExecuteNonQuery methods. Default is "GO". The batch separator is case-insensitive.

CapturedSql CapturedSql CapturedSql Inherited from ConnectionManager
ConnectAsUser ConnectAsUser ConnectAsUser

If set to true, the connection will be made with the credentials of the specified user. This will assume impersonation, however the LoginSecure flags and Login and Password fields will not be affected. ConnectionCannotBeChangedException

(Inherited from ConnectionSettings)
ConnectAsUserName ConnectAsUserName ConnectAsUserName

Specifies the NT user that is used when creating an impersonated connection. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException PropertyNotSetException

(Inherited from ConnectionSettings)
ConnectAsUserPassword ConnectAsUserPassword ConnectAsUserPassword

Specifies password of the NT user that is used when creating an impersonated connection. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException PropertyNotSetException

(Inherited from ConnectionSettings)
ConnectionProtocol ConnectionProtocol ConnectionProtocol

Connection protocol.

(Inherited from ConnectionManager)
ConnectionString ConnectionString ConnectionString

The property will return either the user specified connection string or it will return the computed connection string based on object settings. If explicitly set, All properties in the ServerConnection object will be populated to reflect the passed in connection string. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
ConnectionType ConnectionType ConnectionType
ConnectTimeout ConnectTimeout ConnectTimeout

The length of time (in seconds) to wait for a connection to the server before terminating the attempt and throwing an exception. Default is 30 seconds (same as Shiloh). Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
DatabaseEngineEdition DatabaseEngineEdition DatabaseEngineEdition

The edition of the Database Engine

(Inherited from ConnectionManager)
DatabaseEngineType DatabaseEngineType DatabaseEngineType

Returns the database engine type of SQL Server. Exceptions: ConnectionFailureException

(Inherited from ConnectionManager)
DatabaseName DatabaseName DatabaseName

TBD

(Inherited from ConnectionSettings)
EncryptConnection EncryptConnection EncryptConnection

whether "encrypt=true" is specified in the connection string

(Inherited from ConnectionSettings)
FixedServerRoles FixedServerRoles FixedServerRoles

Returns an enum that specified the fixed server role the login is member of.

HostPlatform HostPlatform HostPlatform

The host platform of the server (Linux/Windows/etc)

(Inherited from ConnectionManager)
InUse InUse InUse

Returns true if the object has been connected with the server at least once. If true, property changes are not allowed any more and ConnectionCannotBeChangedException will be thrown when a property has been changed.

(Inherited from ConnectionManager)
IsActiveDirectoryUniversalAuth IsActiveDirectoryUniversalAuth IsActiveDirectoryUniversalAuth Inherited from ConnectionSettings
IsForceDisconnected IsForceDisconnected IsForceDisconnected

Indicates that the connection has been forcefully disconnected

(Inherited from ConnectionManager)
IsOpen IsOpen IsOpen

Returns true if the SqlConnection object is connected with the server. This can only return true for non pooled connections as pooled connections are always closed directly after an operation.

(Inherited from ConnectionManager)
LockTimeout LockTimeout LockTimeout

LockTimeout is the Lock timeout in seconds. Default -1 is for indefinite. InvalidPropertyValueException is thrown for all other negative numbers. Positive LockTimeout will be multiplied by 1000 and then used for "SET LOCK_TIMEOUT" setting.

(Inherited from ConnectionManager)
Login Login Login

The SQL Server Login name that is used to connect to the server. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException PropertyNotSetException

(Inherited from ConnectionSettings)
LoginSecure LoginSecure LoginSecure

If set to true, Windows integrate security is used and Login and Password are ignored. If not set, Sql Server Authentication is used. Exceptions: ConnectionCannotBeChangedException

(Inherited from ConnectionSettings)
MaxPoolSize MaxPoolSize MaxPoolSize

The maximum number of connections allowed in the pool. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
MinPoolSize MinPoolSize MinPoolSize

The minimum number of connections maintained in the pool. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
MultipleActiveResultSets MultipleActiveResultSets MultipleActiveResultSets

Enable MARS from the connection. Default is false.

(Inherited from ConnectionSettings)
NetworkProtocol NetworkProtocol NetworkProtocol

Identifies the client network protocol that is used to connect to SQL Server. If you do not specify a network and you use a local server, shared memory is used. If you do not specify a network and you use a remote server, the one of the configured client protocols is used. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
NonPooledConnection NonPooledConnection NonPooledConnection

By default, all connections to SQL Server are taken from an ADO.NET connection pool.If set to true, this allows users to create a non-pooled connection (will not be reused when closed). Exceptions: ConnectionCannotBeChangedException

(Inherited from ConnectionSettings)
PacketSize PacketSize PacketSize

Size in bytes of the network packets used to communicate with an instance of SQL Server. Default is 8192. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
ParameterizationMode ParameterizationMode ParameterizationMode
Password Password Password

The password that is used with Login to connect to the server. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException PropertyNotSetException

(Inherited from ConnectionSettings)
PooledConnectionLifetime PooledConnectionLifetime PooledConnectionLifetime

When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by connection lifetime. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
ProcessID ProcessID ProcessID

The ProcessID property returns the SQL Server process identifier for the connection used by the ServerConnection object.

ProductVersion ProductVersion ProductVersion

Gets the ProductVersion server property of this connection

(Inherited from ConnectionManager)
ResetConnectionString ResetConnectionString ResetConnectionString

Tells us whether ConnectionString needs to be reset in SqlConnectionObject property of ConnectionManager or not.

(Inherited from ConnectionSettings)
SecureConnectionString SecureConnectionString SecureConnectionString

The property will return a SecureString version of either the user specified connection string or it will return the computed connection string based on object settings. If explicitly set, All properties in the ServerConnection object will be populated to reflect the passed in connection string. Exceptions: ConnectionCannotBeChangedException

(Inherited from ConnectionSettings)
SecurePassword SecurePassword SecurePassword

The password that is used with Login to connect to the server. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException PropertyNotSetException

(Inherited from ConnectionSettings)
ServerInstance ServerInstance ServerInstance

The name of the SQL Server the object will connect to. If not set, the local server is implied. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)
ServerVersion ServerVersion ServerVersion

Returns the major version number of SQL Server. I.e. 8 for SQL Server 2000. Exceptions: ConnectionFailureException

(Inherited from ConnectionManager)
SqlConnectionObject SqlConnectionObject SqlConnectionObject

Returns a reference to the SqlConnection object used by the ConnectionContext object. This should always return the valid sqlConnection object with the latest valid ConnectionString set. Exceptions: PropertyNotAvailableException

(Inherited from ConnectionManager)
SqlExecutionModes SqlExecutionModes SqlExecutionModes

Determines if SQL statements are captured or sent to the server.

StatementTimeout StatementTimeout StatementTimeout

This is the number of seconds that a statement is attempted to be sent to the server before it fails. Default is 600 seconds (same as Shiloh). Exceptions: InvalidPropertyValueException

TransactionDepth TransactionDepth TransactionDepth

Provides the transaction depth as counted by the object model. This doesn't include any transactions that may have been started on the server, or by issuing BEGIN TRAN with the ExecuteNonQuery method.

TrueLogin TrueLogin TrueLogin

The TrueLogin property returns the login record name used by the current connection.

TrueName TrueName TrueName

The TrueName property returns the result set of the Microsoft® SQL Server global function @@INSTANCENAME.

TrustServerCertificate TrustServerCertificate TrustServerCertificate

Indicate whether the client trusts the server certificate

(Inherited from ConnectionSettings)
UseMode UseMode UseMode
UserProfile UserProfile UserProfile

The UserProfile property returns a high-level role description for the Microsoft SQL Server login used by the current connection.

WorkstationId WorkstationId WorkstationId

The name of the workstation connecting to SQL Server. Exceptions: ConnectionCannotBeChangedException InvalidPropertyValueException

(Inherited from ConnectionSettings)

Methods

BeginTransaction() BeginTransaction() BeginTransaction()

Starts a new transaction. If CaptureMode is true, the transaction statement will be added to the capture buffer.It is possible to nest transactions. It is the user's responsibility to commit or rollback every opened transaction. It is not guaranteed that all T-SQL emitted by the object model, can be encapsulated by a transaction. Furthermore, the state of the objects that have been changed will not reflect the actual database state until a transaction has been committed or after a transaction has been rolled backed. It is the responsibility of the user to refresh affected objects. Use with care.

Cancel() Cancel() Cancel()
ChangePassword(SecureString) ChangePassword(SecureString) ChangePassword(SecureString)
ChangePassword(String) ChangePassword(String) ChangePassword(String)
CheckServerVersion(ServerVersion) CheckServerVersion(ServerVersion) CheckServerVersion(ServerVersion)

Check if we are connecting to a supported server version. block off <= 7.0 in ServerConnection.

(Inherited from ConnectionManager)
CommitTransaction() CommitTransaction() CommitTransaction()

Commits a transaction. If CaptureMode is true, the transaction command will be added to the capture buffer. Exceptions: NotInTransactionException

Connect() Connect() Connect()

Creates the actual connection to SQL Server. Ignored if already connected. It is optional to call this method, as the connection will be opened when required. Exceptions: ConnectionFailureException

(Inherited from ConnectionManager)
Copy() Copy() Copy()

This function performs a deep copy

Disconnect() Disconnect() Disconnect()

Closes the connection with SQL Server. Ignored if already disconnected. Exceptions: ConnectionFailureException

(Inherited from ConnectionManager)
ExecuteNonQuery(String) ExecuteNonQuery(String) ExecuteNonQuery(String)
ExecuteNonQuery(String, ExecutionTypes) ExecuteNonQuery(String, ExecutionTypes) ExecuteNonQuery(String, ExecutionTypes)

Executes a T-SQL statement. The command termininator ('GO') is recognized by ExecuteNonQuery. Batches will be sent and executed individually. The statement is recorded and not executed if CaptureMode has been set to true. An int value is returned that contain the numbers of rows affected. If multiple batches are executed, the total numbers of affected rows of all batches is returned. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteNonQuery(String, ExecutionTypes, Boolean) ExecuteNonQuery(String, ExecutionTypes, Boolean) ExecuteNonQuery(String, ExecutionTypes, Boolean)

Executes a T-SQL statement. The command termininator ('GO') is recognized by ExecuteNonQuery. Batches will be sent and executed individually. The statement is recorded and not executed if CaptureMode has been set to true. An int value is returned that contain the numbers of rows affected. If multiple batches are executed, the total numbers of affected rows of all batches is returned. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteNonQuery(StringCollection) ExecuteNonQuery(StringCollection) ExecuteNonQuery(StringCollection)
ExecuteNonQuery(StringCollection, ExecutionTypes) ExecuteNonQuery(StringCollection, ExecutionTypes) ExecuteNonQuery(StringCollection, ExecutionTypes)

Executes the T-SQL statements in the StringCollection. The command termininator ('GO') is recognized by ExecuteNonQuery. Batches separated with the GO statement will be sent and executed individually. The statement is recorded and not executed if CaptureMode has been set to true. An array of int values is returned that contain the numbers of rows affected for each statement in the StringCollection. If multiple batches are executed, the total numbers of affected rows of all batches is returned. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteNonQuery(StringCollection, ExecutionTypes, Boolean) ExecuteNonQuery(StringCollection, ExecutionTypes, Boolean) ExecuteNonQuery(StringCollection, ExecutionTypes, Boolean)

Executes the T-SQL statements in the StringCollection. The command termininator ('GO') is recognized by ExecuteNonQuery. Batches separated with the GO statement will be sent and executed individually. The statement is recorded and not executed if CaptureMode has been set to true. An array of int values is returned that contain the numbers of rows affected for each statement in the StringCollection. If multiple batches are executed, the total numbers of affected rows of all batches is returned. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteReader(String) ExecuteReader(String) ExecuteReader(String)

Executes T-SQL statements. A SqlDataReader object is returned that can be used to read the stream of rows that are returned by SQL Server. The Connect() method will be called if the connection with the server is not open. it doesn't automatically disconnect Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteReader(String, SqlCommand) ExecuteReader(String, SqlCommand) ExecuteReader(String, SqlCommand)

Executes T-SQL statements. A SqlDataReader object is returned that can be used to read the stream of rows that are returned by SQL Server. A SqlCommand object is also returned that can be used to cancel the data reader pipe if an abort of a long-running query is needed. it doesn't automatically disconnect Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteScalar(String) ExecuteScalar(String) ExecuteScalar(String)

Executes a T-SQL statement. An objects is returned that contains the first column of the first row of the result set. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteScalar(StringCollection) ExecuteScalar(StringCollection) ExecuteScalar(StringCollection)

Executes the T-SQL statements in the StringCollection. An array of objects are returned that each contain the first column of the first row of the result set of each executed statement. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteTSql(ConnectionManager+ExecuteTSqlAction, Object, DataSet, Boolean) ExecuteTSql(ConnectionManager+ExecuteTSqlAction, Object, DataSet, Boolean) ExecuteTSql(ConnectionManager+ExecuteTSqlAction, Object, DataSet, Boolean)

Executes T-SQL using the appropriate methods depending on the action information passed as the parameter.

(Inherited from ConnectionManager)
ExecuteWithResults(String) ExecuteWithResults(String) ExecuteWithResults(String)

Executes the T-SQL statements in sqlCommand. A DataSet is returned that contains the results. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteWithResults(String, Boolean) ExecuteWithResults(String, Boolean) ExecuteWithResults(String, Boolean)

Executes the T-SQL statements in sqlCommand. A DataSet is returned that contains the results. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ExecuteWithResults(StringCollection) ExecuteWithResults(StringCollection) ExecuteWithResults(StringCollection)

Executes the T-SQL statements in the StringCollection. An array of DataSets are returned that contain the results for each statement in the StringCollection. The Connect() method will be called if the connection with the server is not open. Exceptions: ConnectionFailureException ExecutionFailureExeception

ForceDisconnected() ForceDisconnected() ForceDisconnected()

Enforces a disconnect and ensures that connection cannot be re-opened again

(Inherited from ConnectionManager)
GetDatabaseConnection(String, Boolean) GetDatabaseConnection(String, Boolean) GetDatabaseConnection(String, Boolean)

Returns a connection that has the specified database name in the connection string

GetDatabaseConnection(String, Boolean, IRenewableToken) GetDatabaseConnection(String, Boolean, IRenewableToken) GetDatabaseConnection(String, Boolean, IRenewableToken)

Returns a connection that has the specified database name in the connection string

IsInFixedServerRole(FixedServerRoles) IsInFixedServerRole(FixedServerRoles) IsInFixedServerRole(FixedServerRoles)

Tests if login is member of any of the specified server roles.

NormalizeQuery(String) NormalizeQuery(String) NormalizeQuery(String)

Overload for the above function -- see it for details

NormalizeQuery(String, Boolean) NormalizeQuery(String, Boolean) NormalizeQuery(String, Boolean)

Translate a query with embedded literals to a normalized form (all literals replaced by a standard token)

RollBackTransaction() RollBackTransaction() RollBackTransaction()

Aborts a transaction (all changes made will not be saved to the database). If CaptureMode is true, the transaction command will be added to the capture buffer. Exceptions: NotInTransactionException

ThrowIfPropertyNotSet(String, String) ThrowIfPropertyNotSet(String, String) ThrowIfPropertyNotSet(String, String) Inherited from ConnectionSettings
ThrowIfPropertyNotSet(String, String, Boolean) ThrowIfPropertyNotSet(String, String, Boolean) ThrowIfPropertyNotSet(String, String, Boolean) Inherited from ConnectionSettings
ToString() ToString() ToString() Inherited from ConnectionSettings

Explicit Interface Implementations

ISfcConnection.Connect() ISfcConnection.Connect() ISfcConnection.Connect()
ISfcConnection.Copy() ISfcConnection.Copy() ISfcConnection.Copy()
ISfcConnection.Disconnect() ISfcConnection.Disconnect() ISfcConnection.Disconnect()
ISfcConnection.ServerVersion ISfcConnection.ServerVersion ISfcConnection.ServerVersion
ISfcConnection.ToEnumeratorObject() ISfcConnection.ToEnumeratorObject() ISfcConnection.ToEnumeratorObject()

Events

InfoMessage InfoMessage InfoMessage

Occurs when SQL Server returns a warning or informational message. Uses System.Data.SqlClient.SqlInfoMessageEventHandler.

(Inherited from ConnectionManager)
RemoteLoginFailed RemoteLoginFailed RemoteLoginFailed

Called when the server needs to connect to remote servers and the login fails

(Inherited from ConnectionManager)
ServerMessage ServerMessage ServerMessage

Occurs when SQL Server returns a warning or informational message. Uses System.Data.SqlClient.SqlInfoMessageEventHandler.

(Inherited from ConnectionManager)
StateChange StateChange StateChange

Occurs when the state of the connection changes. Uses System.Data.StateChangeEventHandler.

(Inherited from ConnectionManager)
StatementExecuted StatementExecuted StatementExecuted Inherited from ConnectionManager

Fields

NoConnectionTimeout NoConnectionTimeout NoConnectionTimeout

Infinite wait

(Inherited from ConnectionSettings)

Applies to