Table of Contents

Class PolarConnection

Namespace
PolarDataInterop
Assembly
PolarDataInterop.dll

This class is used to communicate with the database.

public class PolarConnection : IDisposable
Inheritance
PolarConnection
Implements
Inherited Members
Extension Methods

Constructors

PolarConnection(string)

Constructor using a specific connection string.

public PolarConnection(string pConnectionString = "")

Parameters

pConnectionString string

The connection string to use.

Fields

OnError

Weak event interface.

public PolarWeakEvent OnError

Field Value

PolarWeakEvent

Properties

AutoCloseConnection

If this property is set to True, the connection is automatically closed as soon as no transactions or recordsets are open. Can be set to false, to keep for example a 'USE' statetment working.

public bool AutoCloseConnection { get; set; }

Property Value

bool

CommandTimeout

Gets/sets the timeout for commands in seconds.

public int CommandTimeout { get; set; }

Property Value

int

Connection

Gets the underlying connection.

public DbConnection Connection { get; }

Property Value

DbConnection

ConnectionString

Returns the underlying connection string.

public string ConnectionString { get; }

Property Value

string

ConnectionTimeout

Gets the timeout for connecting to the database. Read only.

public int ConnectionTimeout { get; set; }

Property Value

int

InTransaction

Returns True if a transaction is open on this connection.

public bool InTransaction { get; }

Property Value

bool

ServerType

Returns the type of server.

public ServerType ServerType { get; }

Property Value

ServerType

Methods

BeginTransaction()

To start a transaction. Only one transaction can be in place.

public bool BeginTransaction()

Returns

bool

A boolean indicating success.

Exceptions

Exception

Throws an error if already in a transaction or if the BEGIN TRANSACTION failed.

Clone()

Clones the connection

public PolarConnection Clone()

Returns

PolarConnection

A cloned connection.

Close()

Closes the connection and frees resources.

public void Close()

CloseOpenRecordsets()

This method closes all still open recordsets. Only workd for SQL Server connections.

public void CloseOpenRecordsets()

CommitTransaction()

Commits the open transaction.

public void CommitTransaction()

Exceptions

Exception

Raises an error if not in a transaction.

Dispose()

Disposal.

public void Dispose()

EasyConnect_Jet(string, string, string, string)

Helper to easily connect to a Microsoft Jet database.

public PolarConnection EasyConnect_Jet(string pDatabasePath, string pMDWpath = "", string pUserName = "", string pPassword = "")

Parameters

pDatabasePath string

The name of the database file to open.

pMDWpath string

The name of the security file (MDW file) to use. Leave empty if not using a security file.

pUserName string

The user name to connect with.

pPassword string

The password to connect with.

Returns

PolarConnection

EasyConnect_SqlServer(string, string, string, string)

Helper to easily connect to a SQL server database.

public PolarConnection EasyConnect_SqlServer(string pServer, string pDataBase, string pUserName = "", string pPassword = "")

Parameters

pServer string

The name of the server to connect to.

pDataBase string

The name of the database to connect to.

pUserName string

The username to connect with. Use an empty string to integrated authentication.

pPassword string

The password to connect with. Use an empty string to integrated authentication.

Returns

PolarConnection

This Polar Connection object.

Execute(string, bool)

This method executes a SQL statetment on the current database.

public void Execute(string pSQL, bool pSuppressNewConnection = false)

Parameters

pSQL string

The SQL statement to execute.

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Execute(string, ref int, bool)

This method executes a SQL statetment on the current database.

public void Execute(string pSQL, ref int pRecordsAffected, bool pSuppressNewConnection = false)

Parameters

pSQL string

The SQL statement to execute.

pRecordsAffected int

This by-ref int parameter will contain the numer of records affected.

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

ExecuteNonQuery(string, bool)

This method executes a SQL statetment on the current database and returns the number of records affected.

public int ExecuteNonQuery(string pSQL, bool pSuppressNewConnection = false)

Parameters

pSQL string

The SQL statement to execute.

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

int

The number of affected records.

ExecuteScalar(string, bool)

This method executes a SQL statetment on the current database and returns the value returned by the database.

public object ExecuteScalar(string pSQL, bool pSuppressNewConnection = false)

Parameters

pSQL string

The SQL statement to execute.

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

object

The returned value.

~PolarConnection()

Disposal

protected ~PolarConnection()

GetCatalog(string, string)

Gets the catalog used to get information about the tables and views in this database.

public bpxCatalog GetCatalog(string pCatalogName = "", string pSchemaName = "dbo")

Parameters

pCatalogName string

The name of the catalog to retrieve.

pSchemaName string

The schema (like 'dbo') to retrieve.

Returns

bpxCatalog

Lookup(string, bool)

This method will execute the given query and return the first field of the first record. If no data is found or an exception was raised, NULL will be returned.

public object Lookup(string pQuery, bool pSuppressNewConnection = false)

Parameters

pQuery string

The query to execute, like 'SELECT COUNT(*) FROM Customer'

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

object

The value of the first field of the first record returned by the query or NULL in all other cases.

Lookup(string, ref int, ref string, bool)

This method will execute the given query and return the first field of the first record. If no data is found or an exception was raised, NULL will be returned.

public object Lookup(string pQuery, ref int pErrorNumber, ref string pErrorMessage, bool pSuppressNewConnection = false)

Parameters

pQuery string

The query to execute, like 'SELECT COUNT(*) FROM Customer'

pErrorNumber int

This by-ref int parameter will be set to the error number if applicable

pErrorMessage string

This by-ref string parameter will be set to the error message if applicable

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

object

The value of the first field of the first record returned by the query or NULL in all other cases.

Open(string)

Sets the connection string to the specified pConnectionString

public void Open(string pConnectionString)

Parameters

pConnectionString string

The connection string to use.

OpenDynamicRecordSet(string)

Opens a dynamic recordset that is normally updatable.

public Recordset OpenDynamicRecordSet(string pQuery)

Parameters

pQuery string

The query to use for this recordset.

Returns

Recordset

The dynamic recordset.

OpenStaticRecordSet(string, bool, bool)

Opens a static RecordSet

public Recordset OpenStaticRecordSet(string pQuery, bool pUpdatable = false, bool pSuppressNewConnection = false)

Parameters

pQuery string

The query to use for the recordset.

pUpdatable bool

Mark the recordset as 'updatable'. This only works for plain queries that include the primary key of the single table that is queried.

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

Recordset

The new static recordset.

RecordExists(string, bool)

This method runs a query and returns True if at least one record was returned. If an exception was raised, this method returns False.

public bool RecordExists(string pQuery, bool pSuppressNewConnection = false)

Parameters

pQuery string

The query to execute, like 'SELECT TOP 1 * FROM Customer WHERE Status = 9'

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

bool

True if the given query returned at least one record.

RecordExists(string, ref int, ref string, bool)

This method runs a query and returns True if at least one record was returned. If an exception was raised, this method returns False.

public bool RecordExists(string pQuery, ref int pErrorNumber, ref string pErrorMessage, bool pSuppressNewConnection = false)

Parameters

pQuery string

The query to execute, like 'SELECT TOP 1 * FROM Customer WHERE Status = 9'

pErrorNumber int

This by-ref int parameter will be set to the error number if applicable

pErrorMessage string

This by-ref string parameter will be set to the error message if applicable

pSuppressNewConnection bool

If not in a transaction and AutoCloseConnection = False, then the recordset will be opened in a clone of this connection, unless this parameter is passed as True.

Returns

bool

True if the given query returned at least one record.

RollBackTransaction()

Rolls back the open transaction.

public void RollBackTransaction()

Exceptions

Exception

Raises an error if not in a transaction.

ToString()

Returns the connection string.

public override string ToString()

Returns

string

ValueToSQL(object)

This method converts a value to a SQL string.

public string ValueToSQL(object pValue)

Parameters

pValue object

The value to convert.

Returns

string

A SQL expression representing the value.