<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.0" />

Microsoft.Data.SqlClient.SqlConnection

public sealed class SqlConnection : DbConnection, ICloneable
Represents a connection to a SQL Server database. This class cannot be inherited.
public static TimeSpan ColumnEncryptionKeyCacheTtl { get; set; }

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.

public static bool ColumnEncryptionQueryMetadataCacheEnabled { get; set; }

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.

public static IDictionary<string, IList<string>> ColumnEncryptionTrustedMasterKeyPaths { get; }

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.

public string AccessToken { get; set; }

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.

public Guid ClientConnectionId { get; }

The connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or failed.

public int CommandTimeout { get; }

Gets the default wait time (in seconds) before terminating the attempt to execute a command and generating an error. The default is 30 seconds.

public SqlCredential Credential { get; set; }

Gets or sets the SqlCredential object for this connection.

public bool FireInfoMessageEventOnUserErrors { get; set; }

Gets or sets the FireInfoMessageEventOnUserErrors property.

public int PacketSize { get; }

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.

public int ServerProcessId { get; }

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.

public bool StatisticsEnabled { get; set; }

When set to true, enables statistics gathering for the current connection.

public string WorkstationId { get; }

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.

public SqlConnection(string connectionString)

Initializes a new instance of the SqlConnection class when given a string that contains the connection string.

public SqlConnection(string connectionString, SqlCredential credential)

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.

public static void ChangePassword(string connectionString, string newPassword)

Changes the SQL Server password for the user indicated in the connection string to the supplied new password.

public static void ClearAllPools()

Empties the connection pool.

public static void ClearPool(SqlConnection connection)

Empties the connection pool associated with the specified connection.

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.

public SqlTransaction BeginTransaction(IsolationLevel iso, string transactionName)

Starts a database transaction with the specified isolation level and transaction name.

public SqlTransaction BeginTransaction(string transactionName)

Starts a database transaction with the specified transaction name.

Creates and returns a SqlCommand object associated with the SqlConnection.

public void Open(SqlConnectionOverrides overrides)

Opens a database connection with the property settings specified by the ConnectionString.

public Task OpenAsync(SqlConnectionOverrides overrides, CancellationToken cancellationToken)

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.

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.

public void ResetStatistics()

If statistics gathering is enabled, all values are reset to zero.

public IDictionary<string, object> RetrieveInternalInfo()

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.