Click or drag to resize

Database Class

The Database object simplifies development tasks that implement common data access functionality.
Inheritance Hierarchy
SystemObject
  NetQuarryDatabase

Namespace:  NetQuarry
Assembly:  EAP.Core (in EAP.Core.dll) Version: 2.0.0.0 (4.6.8.0)
Syntax
[SerializableAttribute]
public class Database : IDatabase, IEAPBase, 
	IDisposable

The Database type exposes the following members.

Constructors
  NameDescription
Public methodDatabase
Default constructor
Top
Properties
  NameDescription
Public propertyApplication
Returns the connected IAppContext object.
Public propertyAttributes
Gets/Sets the Database DatabaseAttrs attributes.
Public propertyCanLogPerformance
Gets/Sets whether the database can begin to log performance requests. If an application is set (via Logging Feature) to utilize a Diagnostic Service, we can't begin logging database requests until the application has completed loading Feature collections. Otherwise the request for features causes a recursion in the database code.
Public propertyCommandTimeout
Gets/Sets the CommandTimeout value.
Public propertyConnection
Gets the string used to open the encapsulated IDbConnection.
Public propertyConnectionString
Gets/Sets the connection string of the enclosed IDbConnection object.
Public propertyDatabaseID
This object's ID. Used primarily to load properties for this database
Public propertyDatabaseName
Gets the name of the database associated with this object.
Public propertyDBMSType
Returns the DBMSType of the currently connected database.
Public propertyDBMSVersionMajor
Gets the DBMS major version number or zero if no version can be determined. Use DBMSVersionMinor to get the minor version number.
Public propertyDBMSVersionMinor
Gets the DBMS minor version number. Note that the minor version number is valid only if DBMSVersionMajor, the major version number, is positive. Use DBMSVersionMajor to get the major version number.
Public propertyIsOpen
Returns True if the underlying connection is open
Public propertyLogDBExecutionCacheHits
Gets/Sets whether the database should log (to devlog) cache hits/misses on DBExecutions (DBLookup, DBExists, DBCount) within same thread context. For Debugging purposes. Use with caution.
Public propertyLogDuplicateDBExecutions
Gets/Sets whether the database should log (to devlog) duplicate requests for DB Executions (DBLookup, DBExists, DBCount) within same thread context. For Debugging purposes. Use with caution.
Public propertyProperties
Returns the object's properties collection
Public propertyProvider
Gets/Sets the Provider name to use when creating the encapsulated IDbConnection.
Public propertyTrackSPID
Gets/Sets whether the database should track connection SPID's. For Debugging purposes. Use with caution.
Top
Methods
  NameDescription
Public methodBeginTransaction
Public methodClone
Make a clone of the current database.
Public methodClose
The Close method closes the underlying Connection object and rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled.
Public methodCommitTransaction
Public methodCode exampleDBCount(String, String, String)
Returns the number of items in the specified column and table using the SQL WHERE clause supplied. Note: For improved performance use DBExists(String, String) when possible.
Public methodCode exampleDBCount(String, String, String, DataFuncOptions, String)
Returns the number of items in the specified column and table using the SQL WHERE clause supplied. Note: For improved performance use DBExists(String, String, DataFuncOptions, String) when possible.
Public methodCode exampleDBCount(String, String, String, DataFuncOptions, String, Int32)
Returns the number of items in the specified column and table using the SQL WHERE clause supplied. Note: For improved performance use DBExists(String, String, DataFuncOptions, String) when possible.
Public methodCode exampleDBCountCache
Returns the number of items in the specified column and table using the SQL WHERE clause supplied. Note: For improved performance use DBExistsCache(String, String, DataFuncOptions, String) when possible. DBCountCache is an enhancement to the existing DBCount function. Ultimately we still use the same DBCount mechanism to retrieve the required value but the result is cached to Thread Local Storage. Subsequent requests to lookup the same count (using the SAME SQL) will pull that value from the thread cache rather than hitting the database.
Public methodDBExists(String, String)
Determines if a particular record exists. For better performance and clarity, use this instead of DBCount(String, String, String) to determine if a record or records exist.
Public methodDBExists(String, String, DataFuncOptions)
Determines if a particular record exists. For better performance and clarity, use this instead of DBCount(String, String, String, DataFuncOptions, String) to determine if a record or records exist.
Public methodDBExists(String, String, DataFuncOptions, String)
Determines if a particular record exists. For better performance and clarity, use this instead of DBCount(String, String, String, DataFuncOptions, String) to determine if a record or records exist.
Public methodDBExistsCache
Determines if a particular record exists. For better performance and clarity, use this instead of DBCount(String, String, String, DataFuncOptions, String) to determine if a record or records exist. DBExistsCache is an enhancement to the existing DBExists function. Ultimately we still use the same DBExists mechanism to retrieve the required value but the result is cached to Thread Local Storage. Subsequent requests to check existence of the same value (using the SAME SQL) will pull that value from the thread cache rather than hitting the database.
Public methodCode exampleDBLookup(String, String, String)
You can use the DBLookup function to get the value of a particular column from a specified set of records (a domain).
Public methodCode exampleDBLookup(String, String, String, DataFuncOptions, String)
You can use the DBLookup function to get the value of a particular column from a specified set of records (a domain).
Public methodCode exampleDBLookup(String, String, String, DataFuncOptions, String, String)
You can use the DBLookup function to get the value of a particular column from a specified set of records (a domain).
Public methodCode exampleDBLookupCache
DBLookupCache is an enhancement to the existing DBLookup function. Ultimately we still use the same DBLookup mechanism to retrieve the required value but the result is cached to Thread Local Storage. Subsequent requests to lookup the same value (using the SAME SQL) will pull that value from the thread cache rather than hitting the database.
Public methodDispose
Close the database connection(s)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExec
Execute a DatabaseExecCommands command on the object.
Public methodExecute(String)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, String)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, ExecuteOptions, String)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, String, Int32)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, ExecuteOptions, String, String)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, ExecuteOptions, String, String, Int32)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, ExecuteOptions, String, String, String)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, ExecuteOptions, String, String, String, Int32)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecute(String, ExecuteOptions, String, String, String, Int32, Int32)
You can use the Execute method to perform catalog operations (for example, creating database objects such as tables), or to change the data in a database without using a DataSet by executing UPDATE, INSERT, or DELETE statements.

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.
Public methodExecuteScalar(String, String)
Execute a scalar SQL statement (a statement that returns a single item).
Public methodExecuteScalar(String, String, Int32)
Execute a scalar SQL statement (a statement that returns a single item).
Public methodExecuteThroughAdapter(String, String, Hashtable, ExecuteThroughAdapterAttrs)
Executes an insert, update or delete through IDbDataAdapter, Dataset, DataTable, DataRow
Public methodExecuteThroughAdapter(String, String, Hashtable, ExecuteThroughAdapterAttrs, String)
Executes an insert, update or delete through IDbDataAdapter, Dataset, DataTable, DataRow
Public methodFillStringCollection
Fill a StringCollection with the contents of the first column in the provided query. Note that each value will be converted to a string.
Protected methodFinalize
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFireAndForget(String, ExecuteOptions, String)
Execute the specified SQL asynchronously. The SQL execution is spun off to the thread pool to be executed when a thread becomes available, and control is returned to the caller immediately. Note that there is no way to get the result, or success/failure of the execution except to query if from the database.
Public methodFireAndForget(String, ExecuteOptions, String, FireAndForgetOptions)
Execute the specified SQL asynchronously. The SQL execution is spun off to the thread pool to be executed when a thread becomes available, and control is returned to the caller immediately. Note that there is no way to get the result, or success/failure of the execution except to query if from the database.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetSchemaInfo(String)
Gets a SchemaInfoCollection describing the specified table or view with SchemaInfo objects for each column. Note that schema information is cached on demand and per-DatabaseID. If the specified table does not exist then an empty (but not null) SchemaInfoCollection will be returned and you can test ObjectExists to determine whether or not the object exists. You can use GetSchemaInfo(String, SchemaInfoType) for various schema object, including tables and views.
Public methodGetSchemaInfo(String, SchemaInfoType)
Gets a SchemaInfoCollection describing the specified database object with SchemaInfo objects for each column or input parameter. Note that schema information is cached on demand and per-DatabaseID. If the specified table does not exist then an empty (but not null) SchemaInfoCollection will be returned and you can test ObjectExists to determine whether or not the object exists.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodHibernate
Public methodLoadFile
Load the specified file data into a memory stream. If no records are found then the stream object will be created, but will be empty. If multiple records are found then data will be loaded from the first record only.
Public methodLoadProperties
Loads the database Properties from the repository database.
Public methodLogPerformance
Logs the duration of an event into the Performance Monitoring System
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodOpen
Opens the connection to the underlying data source.
Public methodOpen(IAppContext, String)
Opens the connection to the underlying data source.
Public methodOpen(IAppContext, String, DatabaseOpenOptions)
Opens the connection to the underlying data source.
Public methodOpenCachedTable(String, String)
Opens a new DataSet and returns the first DataTable, retrieving it from the cache if it is cached. If the object is not cached, it is opened from the datasource and added to the global cache.
Public methodOpenCachedTable(String, String, String)
Opens a new DataSet and returns the first DataTable, retrieving it from the cache if it is cached. If the object is not cached, it is opened from the datasource and added to the global cache.
Public methodOpenCachedTable(String, String, String, Boolean)
Opens a new DataSet and returns the first DataTable, retrieving it from the cache if it is cached. If the object is not cached, it is opened from the datasource and added to the global cache.
Public methodOpenDataReader(String)
Opens a recordset using the internal connection and default options.
Public methodOpenDataReader(String, String)
Opens a recordset using the internal connection and default options.
Public methodOpenDataReader(String, DataFuncOptions, String)
Opens a recordset using the internal connection.
Public methodOpenDataReader(String, String, Int32)
Opens a recordset using the internal connection.
Public methodOpenDataReader(String, IDbConnection, DataFuncOptions, String)
Opens a recordset using the specified connection.
Public methodOpenDataReader(String, IDbConnection, DataFuncOptions, String, String)
Opens a recordset using the specified connection.
Public methodOpenDataReader(String, IDbConnection, DataFuncOptions, String, String, Int32)
Opens a recordset using the specified connection.
Public methodOpenDataset(String)
Opens one or more tables or views.
Public methodOpenDataset(String, String)
Opens one or more tables or views.
Public methodOpenDataset(String, String, Int32)
Opens one or more tables or views.
Public methodOpenHashtable
Opens a 2 column statement on the encapsulated connection and returns the results as a hashtable. Note that a hashtable is ALWAYS returned even if no records were found (in which case it will be empty).
Public methodOpenTable(String)
Opens a new DataSet and returns the first DataTable. If caching is appropriate use OpenCachedTable(String, String) for improved performace.
Public methodOpenTable(String, String)
Opens a new DataSet and returns the first DataTable. If caching is appropriate use OpenCachedTable(String, String, String) for improved performace.
Public methodOpenTable(String, String, Int32)
Opens a new DataSet and returns the first DataTable. If caching is appropriate use OpenCachedTable(String, String, String) for improved performace.
Public methodResolveEmbeddedFunction
Resolve a SQL string for embedded functions. See EmbeddedParser for more information on embedded functions.
Public methodRollbackTransaction
Public methodTableSpace
Gets the space used by the specified table. Currently this method is only supported for SQL-Server where the sp_spaceused stored procedure is used. For non-supported DBMS's, an empty (non-null) space descriptor is returned. At this time, an exception is thrown if the table does not exist, but this behaviour may change in the future and is not guaranteed.
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Public methodWakeUp
Top
Extension Methods
  NameDescription
Public Extension MethodEqualValue
Determines if the object value is equal to another object. If the two objects are null, then this returns true. There is special handling for guid comparisons (since a guid could be a string formatted in up to 3 different ways). If the special guid handling is not performed, then the object.Equals method is used.
(Defined by EAPUtil.)
Top
Remarks

Application extensions can use this class in a variety of situations, such as reading data for display, passing data through application layers, and submitting changed data back to the database system. The class includes support for both stored procedures and in-line SQL.

Common housekeeping tasks, such as managing connections, are encapsulated in the class' methods. In other words, the Database class provides access to the most often used features of ADO.NET in simple-to-use classes; this boosts developer productivity.

ADO.NET 2.0 provides classes such as the DbCommand class and the DbConnection class; these classes help to abstract the data provider from any particular database implementation. The Database class takes advantage of these classes and provides a model that further supports encapsulation of database type-specific features, such as type conversions. Because of this, applications can be ported from one database type to another without modifying the client code.

The Database class includes an abstract base class that defines a common interface and that provides much of the implementation needed by the data access methods available in ADO.NET 2.0.

The Database class provides the following benefits:

  • It uses the functionality provided by ADO.NET 2.0 and with it, you can use ADO.NET functionality along with the Databases functionality.
  • It reduces the need to write boilerplate code to perform standard tasks.
  • It helps maintain consistent data access practices.
  • It reduces difficulties in changing the database type.
  • It relieves developers from learning different programming models for different types of databases.
  • It reduces the amount of code that developers must write when they port applications to different types of databases.
Examples
The following code snippet shows how to safely open a DataReader and fill a Dictionary object:
IDatabase db = appContext.Databases["Studio"];
System.Collections.Generic.Dictionary<string, string> props = new System.Collections.Generic.Dictionary<string, string>();
IDataReader dr = null;

try
{
    using (dr = db.OpenDataReader("SELECT prop_id, prop_value FROM xmt_properties WHERE prop_value is not null"))
    {
        while (dr.Read())
        {
            props.Add(dr.GetString(0), dr.GetString(1));
        }
        dr.Close();
    }
    dr = null;
}
catch (Exception ex)
{
    DevLog.LogMessage("OpenProperties", "dataReadError", ex);
    throw;
}
finally
{
    if (dr != null)
        dr.Close();
}
See Also