SqlServerDbAccess

Implements the IDbAccess functionality for Microsoft SQL Server database engine.

Namespace:
Inetdev.Data.SqlServer
Type:
Class
Public:
Yes
Protected:
No
Sealed:
No
Abstract:
No
Inherits from:
Inetdev.Data.AbstractDbAccess

Constructors

SqlServerDbAccess

Default constructor

Signature:
public Void SqlServerDbAccess()

SqlServerDbAccess

Initializes a new instance of SqlServerDbAccess copying the data from source.

Signature:
public Void SqlServerDbAccess(source)
Parameters
Name Type Summary
source SqlServerDbAccess A SqlServerDbAccess to be copied.
Exceptions
Type Summary
ArgumentNullException Thrown when source is null.

Properties

Encrypt

Whether the connection is encrypted.

Signature:
public Nullable<Boolean> Encrypt { get; set; }

FailoverPartner

Name or address of the partner server to connect to if the primary server is down.

Signature:
public String FailoverPartner { get; set; }

IsConnectionOpen

Get whether the database connection is opened.

Signature:
public Boolean IsConnectionOpen { get; }

IsInTransaction

Get whether an opened connection is running a transaction.

Signature:
public Boolean IsInTransaction { get; }

Password

Password of the user used to connect to the database.

Signature:
public String Password { set; }

TrustServerCertificate

Whether to trust on server certificate.

Signature:
public Nullable<Boolean> TrustServerCertificate { get; set; }

UserName

User name to connecto to the database.

Signature:
public String UserName { set; }

Methods

AddParameter

Adds a new parameter to the command passed as parameter.

Signature:
public Void AddParameter(command, name, type, direction, size, value)
Parameters
Name Type Summary
command IDbCommand The command where the parameter will be added.
name String The quoted parameter name.
type DbType The parameter data type.
direction ParameterDirection The parameter direction.
size Int32 The size of the data in the valueparameter.
value Object The value of the parameter.
Exceptions
Type Summary
DataAccessException Thrown when there are an error casting the parameter value.

BeginTransaction

Initiates a database transaction.

Signature:
public IDbTransaction BeginTransaction()
Returns

An object representing the new transaction.

BeginTransaction

Initiates a database transaction with the specified isolation level.

Signature:
public IDbTransaction BeginTransaction(iso)
Returns

An object representing the new transaction.

Parameters
Name Type Summary
iso IsolationLevel Isolation level for the transaction.

CloseConnection

Closes the database connection if it is opened.

Signature:
public Void CloseConnection()

CommitTransaction

Commits the running database transaction.

Signature:
public Void CommitTransaction()

CreateCommand

Creates a new database command.

Signature:
public IDbCommand CreateCommand(commandType)
Returns

An object representing the newly created command.

Parameters
Name Type Summary
commandType CommandType Type of the command to create.

Dispose

Performs applicarion-defined tasks associated with freeing, releasing, or reseting unmaneged resources.

Signature:
public Void Dispose()

ExecuteCommand

Executes the specified command against the database.

Signature:
public Int32 ExecuteCommand(command, tbl)
Returns

Amount of records affected by the command.

Remarks

If the command returns a set of records, the tbl parameter must contain an initialize DataTable, otherwise it must be null

Parameters
Name Type Summary
command IDbCommand Command to excecute.
tbl DataTable An initialized DataTable object or null.
Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.
OpenConnectionException Thrown when a connection could not be openned.
DuplicatedPrimaryKeyException Thrown when a primary key or unique index constraint fails.
ConstraintViolationException Thrown if a constraint is violated.
DatabaseObjectNotFoundException Thrown when a database object, as a table, view, field, etc., does not exist.

ExecuteCommandAsync

Executes the specified command asyncronously againt the database.

Signature:
public Task<Int32> ExecuteCommandAsync(command, dataTable)
Remarks

If the command returns a set of records, the dataTable parameter must contain an initialized DataTable, otherwise it must be null.

Parameters
Name Type Summary
command IDbCommand Command to execute.
dataTable DataTable An initialized DataTable object or null.
Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.
DuplicatedPrimaryKeyException Thrown when a primary key or unique index constraint fails.
ConstraintViolationException Thrown if a constraint is violated.
DatabaseObjectNotFoundException Thrown when a database object, as a table, view, field, etc., does not exist.

ExecuteReader

Executes the specified command against the database and returns a IDataReader.

Signature:
public IDataReader ExecuteReader(command)
Returns

A read only forward only IDataReader with the database data.

Parameters
Name Type Summary
command IDbCommand Command to execute.
Exceptions
Type Summary
InvalidOperationException Thrown the the connection is not open.
DataAccessException Thrown when an unindentify error occurs.
DatabaseObjectNotFoundException Thrown when a database object, as a table, view, field, etc., does not exist.

ExecuteReaderAsync

Executes the specified command against the database asyncronously and returns an IDataReader.

Signature:
public Task<IDataReader> ExecuteReaderAsync(command)
Parameters
Name Type Summary
command IDbCommand Command to execute.
Exceptions
Type Summary
InvalidOperationException Thrown when the database connection is not open.
DataAccessException Thrown when an unindentify error occurs.
DatabaseObjectNotFoundException Thrown when a database object, as a table, view, field, etc., does not exist.

ExecuteScalar

Executes the specified command against the database and returns the first fields of the first record retrieved.

Signature:
public Object ExecuteScalar(command)
Returns

Value of the first field of the first record. If the CommandType is a Stored Procedure the value of the parameter with Direction equals to ReturnValue is returned.

Parameters
Name Type Summary
command IDbCommand Command to excecute.
Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.
OpenConnectionException Thrown when a connection could not be openned.
DatabaseObjectNotFoundException Thrown when a database object, as a table, view, field, etc., does not exist.

ExecuteScalarAsync

Executes the specified command againts the database asyncronously and returns the first field of the first record retrieved.

Signature:
public Task<Object> ExecuteScalarAsync(command)
Returns

Value of the first field of the first record. If the CommandType is a Stored Procedure the value of the parameter with Direction equals to ReturnValue is returned.

Parameters
Name Type Summary
command IDbCommand Command to execute.
Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.
OpenConnectionException Thrown when a connection could not be openned.
DatabaseObjectNotFoundException Thrown when a database object, as a table, view, field, etc., does not exist.

GetSchema

Ejecutes the underlaying connection GetSchema() method.

Signature:
public DataTable GetSchema()
Returns

A DataTable as obtained from the GetSchema() method.

Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.

GetSchema

Ejecutes the underlaying connection GetSchema() method.

Signature:
public DataTable GetSchema(collectionName)
Returns

A DataTable as obtained from the GetSchema() method.

Parameters
Name Type Summary
collectionName String The name of the collection to retrieve.
Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.

GetSchema

Ejecutes the underlaying connection GetSchema() method.

Signature:
public DataTable GetSchema(collectionName, restrictionValues)
Returns

A DataTable as obtained from the GetSchema() method.

Parameters
Name Type Summary
collectionName String The name of the collection to retrieve.
restrictionValues String[] A set of restriction values.
Exceptions
Type Summary
DataAccessException Thrown when an unindentify error occurs.

GetServerVersion

Gets the server version.

Signature:
public String GetServerVersion()
Returns

The server version.

Remarks

This method returns the compatibility level of the database configured in the DataAccessAPI property as:
When 65 then SQL Server 6.5
When 70 then SQL Server 7.0
When 80 then SQL Server 2000
When 90 then SQL Server 2005
When 100 then SQL Server 2008/2008R2
When 110 then SQL Server 2012
When 120 then SQL Server 2014
When 130 then SQL Server 2016
When 140 then SQL Server 2017
Else new unknown.

Exceptions
Type Summary
SchemaManipulationException Thrown when there is an error accesing schema data.
MissingRequiredPropertyException Thrown when the Catalog is not initialized.

OpenConnection

Opens a connection with the database server.

Signature:
public Void OpenConnection()
Exceptions
Type Summary
OpenConnectionException Thrown when an unindentify error occurs.
ServerUnavailableException Thrown when the database server is not found.
CatalogNotFoundException Thrown when the catalog is not found.
InvalidCredentialsException Thrown when credentials are invalid.
CredentialsExpiredException Thrown when the password has expired.

OpenConnectionAsync

Opens a connection with the database server asyncronously.

Signature:
public Task OpenConnectionAsync()
Exceptions
Type Summary
OpenConnectionException Thrown when an unindentify error occurs.
ServerUnavailableException Thrown when the database server is not found.
CatalogNotFoundException Thrown when the catalog is not found.
InvalidCredentialsException Thrown when credentials are invalid.
CredentialsExpiredException Thrown when the password has expired.

RollbackTransaction

Aborts the current transaction.

Signature:
public Void RollbackTransaction()