SqlServerConnection

SQLServer connection using the official driver.

Inherits: IReferenceable, IConfigurable, IOpenable

Description

The SqlServerConnection class allows you to create a connection to an SQL Server database using the official driver.

Important points

  • By defining a connection and sharing it through multiple persistence components you can reduce the number of used database connections.

Configuration parameters

connection(s):

  • discovery_key: (optional) key to retrieve the connection from IDiscovery
  • host: host name or IP address
  • port: port number (default: 27017)
  • uri: resource URI or connection string with all parameters in it

credential(s):

  • store_key: (optional) key to retrieve the credentials from ICredentialStore
  • username: username
  • password: user’s password

options:

  • max_pool_size: (optional) maximum connection pool size (default: 2)
  • keep_alive: (optional) enable connection keep alive (default: true)
  • connect_timeout: (optional) connection timeout in milliseconds (default: 5 sec)
  • auto_reconnect: (optional) enable auto reconnection (default: true)
  • max_page_size: (optional) maximum page size (default: 100)
  • debug: (optional) enable debug output (default: false).

References

  • *:logger:*:*:1.0 - (optional) ILogger components to pass log messages
  • *:discovery:*:*:1.0 - (optional) IDiscovery services
  • *:credential-store:*:*:1.0 (optional) credential stores to resolve credentials

Fields

_connection

SQL Server connection pool object.

protected _connection: SqlConnection

_connectionResolver

Connection resolver.

protected _connectionResolver: SqlServerConnectionResolver

_databaseName

SQL Server database name.

protected _databaseName: string

_logger

Logger.

protected _logger: CompositeLogger

_options

Configuration options.

protected _options: ConfigParams

Instance methods

CloseAsync

Closes a component and frees used resources.

public virtual Task CloseAsync(string correlationId)

  • correlationId: string - (optional) transaction id used to trace execution through the call chain.

Configure

Configures a component by passing its configuration parameters.

public virtual void Configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

GetConnection

Gets the connection to an SQL Server database.

public SqlConnection GetConnection()

  • returns: SqlConnection - connection to an SQL Server database.

GetDatabaseName

Gets the name of an SQL Server database.

public string GetDatabaseName()

  • returns: string - database’s name.