Microsoft.Data.SqlClient.SqlConnection
Represents a connection to a SQL Server database. This class cannot be inherited.
Gets or sets the time-to-live for column encryption key entries in the column encryption key cache for the Always Encrypted feature. The default value is 2 hours. 0 means no caching at all.
Gets or sets a value that indicates whether query metadata caching is enabled (true) or not (false) for parameterized queries running against Always Encrypted enabled databases. The default value is true.
Allows you to set a list of trusted key paths for a database server. If while processing an application query the driver receives a key path that is not on the list, the query will fail. This property provides additional protection against security attacks that involve a compromised SQL Server providing fake key paths, which may lead to leaking key store credentials.
Gets or sets the access token for the connection.
public Func<SqlAuthenticationParameters, CancellationToken, Task<SqlAuthenticationToken>> AccessTokenCallback { get; set; }
Gets or sets the access token callback for the connection.
The connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or failed.
Gets the default wait time (in seconds) before terminating the attempt to execute a command and generating an error. The default is 30 seconds.
Gets or sets the SqlCredential object for this connection.
Gets or sets the FireInfoMessageEventOnUserErrors property.
Gets the size (in bytes) of network packets used to communicate with an instance of SQL Server.
Gets or sets a value that specifies the SqlRetryLogicBaseProvider object bound to this command.
Gets the server process ID (SPID) of the active connection.
Gets or sets the SspiContextProvider instance for customizing the SSPI context. If not set, the default for the platform will be used.
When set to true, enables statistics gathering for the current connection.
Gets a string that identifies the database client.
Occurs when SQL Server returns a warning or informational message.
public SqlConnection()
Initializes a new instance of the SqlConnection class.
Initializes a new instance of the SqlConnection class when given a string that contains the connection string.
Initializes a new instance of the SqlConnection class given a connection string, that does not use Integrated Security = true and a SqlCredential object that contains the user ID and password.
public static void ChangePassword(string connectionString, SqlCredential credential, SecureString newSecurePassword)
Changes the SQL Server password for the user indicated in the SqlCredential object.
Changes the SQL Server password for the user indicated in the connection string to the supplied new password.
Empties the connection pool.
Empties the connection pool associated with the specified connection.
public static void RegisterColumnEncryptionKeyStoreProviders(IDictionary<string, SqlColumnEncryptionKeyStoreProvider> customProviders)
Registers the column encryption key store providers. This function should only be called once in an app. This does shallow copying of the dictionary so that the app cannot alter the custom provider list once it has been set.
The built-in column master key store providers that are available for the Windows Certificate Store, CNG Store and CSP are pre-registered.
Starts a database transaction.
Starts a database transaction with the specified isolation level.
Starts a database transaction with the specified isolation level and transaction name.
Starts a database transaction with the specified transaction name.
Creates and returns a SqlCommand object associated with the SqlConnection.
Opens a database connection with the property settings specified by the ConnectionString.
An asynchronous version of Open, which opens a database connection with the property settings specified by the ConnectionString. The cancellation token can be used to request that the operation be abandoned before the connection timeout elapses. Exceptions will be propagated via the returned Task. If the connection timeout time elapses without successfully connecting, the returned Task will be marked as faulted with an Exception. The implementation returns a Task without blocking the calling thread for both pooled and non-pooled connections.
public void RegisterColumnEncryptionKeyStoreProvidersOnConnection(IDictionary<string, SqlColumnEncryptionKeyStoreProvider> customProviders)
Registers the encryption key store providers on the SqlConnection instance. If this function has been called, any providers registered using the static RegisterColumnEncryptionKeyStoreProviders methods will be ignored. This function can be called more than once. This does shallow copying of the dictionary so that the app cannot alter the custom provider list once it has been set.
If statistics gathering is enabled, all values are reset to zero.
Returns a name value pair collection of internal properties at the point in time the method is called.
Returns a name value pair collection of statistics at the point in time the method is called.