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(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)

Constructs a new ServerConnection object from the given SqlConnection

ServerConnection(SqlConnection)

Constructs a new ServerConnection object from the given SqlConnection

ServerConnection(SqlConnection, IRenewableToken)

Constructs a new ServerConnection object

ServerConnection(SqlConnection, IRenewableToken)

Constructs a new ServerConnection object

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

Fields

NoConnectionTimeout

Infinite wait

(Inherited from ConnectionSettings)

Properties

AccessToken (Inherited from ConnectionSettings)
ApplicationIntent

The application intent of the connection Valid values are ReadWrite and ReadOnly

(Inherited from ConnectionSettings)
ApplicationName

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

(Inherited from ConnectionSettings)
Authentication

The authentication type of the connection

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

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

CachedQueries

Gets or sets a value indicating whether ServerConnection instances should cache query results

CapturedSql (Inherited from ConnectionManager)
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

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

(Inherited from ConnectionSettings)
ConnectAsUserPassword

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

(Inherited from ConnectionSettings)
ConnectionProtocol

Connection protocol.

(Inherited from ConnectionManager)
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
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)
CurrentDatabase

Returns the current database context.

(Inherited from ConnectionManager)
DatabaseEngineEdition

The edition of the Database Engine

(Inherited from ConnectionManager)
DatabaseEngineType

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

(Inherited from ConnectionManager)
DatabaseName

TBD

(Inherited from ConnectionSettings)
EncryptConnection

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

(Inherited from ConnectionSettings)
FixedServerRoles

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

HostPlatform

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

(Inherited from ConnectionManager)
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)
IsContainedAuthentication

Returns true if the database engine authenticates using contained authentication. Exceptions: ConnectionFailureException

(Inherited from ConnectionManager)
IsForceDisconnected

Indicates that the connection has been forcefully disconnected

(Inherited from ConnectionManager)
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 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

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

(Inherited from ConnectionSettings)
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

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

(Inherited from ConnectionSettings)
MinPoolSize

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

(Inherited from ConnectionSettings)
MultipleActiveResultSets

Enable MARS from the connection. Default is false.

(Inherited from ConnectionSettings)
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

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

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

Gets or sets a value indicating the QueryParameterizationMode QueryParameterizationMode all ServerConnection instances use

Password

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

(Inherited from ConnectionSettings)
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

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

ProductVersion

Gets the ProductVersion server property of this connection

(Inherited from ConnectionManager)
ResetConnectionString

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

(Inherited from ConnectionSettings)
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

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

(Inherited from ConnectionSettings)
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

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

(Inherited from ConnectionManager)
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

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

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

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

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

TrueName

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

TrustServerCertificate

Indicate whether the client trusts the server certificate

(Inherited from ConnectionSettings)
UseMode

Gets or sets the DeferredUseMode UseMode all ServerConnection instances use

UserProfile

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

WorkstationId

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

(Inherited from ConnectionSettings)

Methods

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()
ChangePassword(SecureString)
ChangePassword(String)
CheckServerVersion(ServerVersion)

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

(Inherited from ConnectionManager)
CommitTransaction()

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

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()

This function performs a deep copy

Disconnect()

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

(Inherited from ConnectionManager)
ExecuteNonQuery(String)
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)

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, 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)

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)

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)

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

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)

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)

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)

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

(Inherited from ConnectionManager)
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)

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)

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()

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

(Inherited from ConnectionManager)
GetDatabaseConnection(String, Boolean)

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

GetDatabaseConnection(String, Boolean, IRenewableToken)

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

IsInFixedServerRole(FixedServerRoles)

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

NormalizeQuery(String)

Overload for the above function -- see it for details

NormalizeQuery(String, Boolean)

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

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) (Inherited from ConnectionSettings)
ThrowIfPropertyNotSet(String, String, Boolean) (Inherited from ConnectionSettings)
ToString() (Inherited from ConnectionSettings)

Events

InfoMessage

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

(Inherited from ConnectionManager)
RemoteLoginFailed

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

(Inherited from ConnectionManager)
ServerMessage

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

(Inherited from ConnectionManager)
StateChange

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

(Inherited from ConnectionManager)
StatementExecuted (Inherited from ConnectionManager)

Explicit Interface Implementations

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

Applies to