QuickObjects.DBLibrary Send comments on this topic.
DatabaseObjectSQL Class Members
See Also  Properties  Methods 
Akal.QuickObjects.DBLibrary Namespace : DatabaseObjectSQL Class


The following tables list the members exposed by DatabaseObjectSQL.

Public Constructors

 NameDescription
Public ConstructorDatabaseObjectSQL ConstructorOverloaded. DatabaseObjectSQL

Default constructor for this class. Calls the parent class's contructor with same signature.  

Top

Public Properties

 NameDescription
Public PropertyAffectedRecords

AffectedRecords

Holds an Int32 value which can be used to hold the number of records that are either returned or affected by a query.

This can be very useful in cases where a count of returned rows is needed.


myLabel.Text = myBusinessObject.AffectedRecords.ToString() + " records were returned by your search";
(Inherited from DatabaseObject)
Public PropertyConnectionString

ConnectionString

Holds the value for connection String used to make a connection to the target database.

This property is automatically initialized with the value from the application configuration settings. The value of ConnectionStringConfigName is used to look for the connection String from the application settings (AppSettings/Keys in Framework 1.1 and ConnectionSettings/Connections in Framework 2.0)..

This property can also be manually set to point the library to a database other than the default. This will be useful if you need the library to connect to multiple database.


myBusinessObj.ConnectionString = "Server=.\SQLExpress;Database=SqlSample;User ID=my_id;Password=my_pass;User Instance=false;
(Inherited from DatabaseObject)
Public PropertyConnectionStringConfigNameConnectionStringConfigName

Set this property to change the name of the connection String. By default the library looks for a "database" connection String (AppSettings/Keys in Framework 1.1 and ConnectionStrings in Framework 2.0). This property should be modified before the database connection is initiated. (Inherited from DatabaseObject)

Public PropertyDatabaseTypeConfigNameDatabaseTypeConfigName

Set this property to change the name of the AppSettings key that contains the database type information. By default the library looks for a "database_type" AppSettings key. (Inherited from DatabaseObject)

Public PropertyDBConnectionDBConnection

Holds any IDbConnection object. This is autmatically created based on the DBType selection.

If the DBType is set to SQL Server 2000 or SQL 2005, this property will be assigned a SqlConnection object, but if the DBType is set to Oracle 8i, 9i or 10g this property will be assigned an OracleConnection.

If you like to manually set the connection you can do so as well as Int64 as the underlying database type remains the same as the value of DBType.


myBusiessObj.DBType = DBTypes.Sql2005;
myBusinessObj.DBConnection = new SqlConnection();

Or


myBusinessObj.DBType = DBTypes.Oracle10g;
myBusinessObj.DBConnection = new OracleConnection();

NOTE: This property is not NonSerializable and it is also ignored during Xml Serialization.  

Public PropertyDBTransaction

DBTransaction

Holds any IDbTransaction compatible object. This is autmatically created based on the value set in UseInTransaction property. If the UseInTransaction property is set to true, then at the time of creating a connection a new Transaction object will be created.

If you like to manually set the transaction object you can do so, although it is better to let the library handle the transaction object creation along with the connection object creation.


myBusinessObj.DBTransaction = myBusinessObj.DBConnection.BeginTransaction();

NOTE: This property is not NonSerializable and it is also ignored during Xml Serialization.

 
Public PropertyDBTypeDBType

Specifies the uderlying database server that will be used by this library. (Inherited from DatabaseObject)

Public PropertyErrorString

ErrorString

Holds a String value. This value is used to store the errors that were encountered while working with any of the database objects.


myErrLabel.Text = this.ErrorString;
(Inherited from DatabaseObject)
Public PropertyFillSchemaFillSchema

Value of FillSchema determines weather after running a SELECT statement if the FillSchema method will be called to fill the underlying schema into the dataset.

NOTE: This is set to false by default.  

Public PropertyParameterPrefix ParameterPrefix - Returns the prefix that can be used to prefix the parameter names  
Public PropertySessionEndCommandSessionEndCommand

Holds a SQL command String or the name of the stored procedure that is executed at the time database connection is closed/destroyed. Hence if the connection is shared by multiple objects, the command is only run once.  

Public PropertySessionEndCommandTypeSessionEndCommandType

Holds a CommandType that indicates weather the SessionEndCommand is of type Text or Stored Procedure. TableDirect command type is not supported.  

Public PropertySessionEndParametersSessionEndParameters

Holds either a Hashtable or an ArrayList of IDataParameters. If a Hashtable is assigned it should contain Key and Value pairs for parameters that the SessionStartCommand expects. Using a hashtable the stored procedure can not return any values and only inbound parameters can be used.

If a ArrayList of parameter objects is used the ArrayList should contain an instance of parameter object for each parameter that SessionStartCommand expects. The parameter objects can be both inbound or outbound and may be of any data type that the underlying database supports.

NOTE: To create an instance of the parameter of type that is suitable for your currently selected database type, call the GetNewParameterInstance method of this object. For example: IDataParameter param = databaseObjectSQL.GetNewParameterInstance();

By using the GetNewParameterInstance you are not hard coding the database specific parameter type, hence if you ever decide to move the underlying data store to a different data store (e.g. move from SQL Server to Oracle or vice versa), you will NOT need to recompile and the application will continue to work.  

Public PropertySessionStartCommandSessionStartCommand

Holds a SQL command String or the name of a stored procedure that is executed at the time database connection is created. Hence if the connection is shared by multiple objects, the command is only run once.  

Public PropertySessionStartCommandTypeSessionStartCommandType

Holds a CommandType that indicates weather the SessionStartCommand is of type Text or Stored Procedure. TableDirect command type is not supported.  

Public PropertySessionStartParametersSessionStartParameters

Holds either a Hashtable or an ArrayList of IDataParameters. If a Hashtable is assigned it should contain Key and Value pairs for parameters that the SessionStartCommand expects. Using a hashtable the stored procedure can not return any values and only inbound parameters can be used.

If a ArrayList of parameter objects is used the ArrayList should contain an instance of parameter object for each parameter that SessionStartCommand expects. The parameter objects can be both inbound or outbound and may be of any data type that the underlying database supports.

NOTE: To create an instance of the parameter of type that is suitable for your currently selected database type, call the GetNewParameterInstance method of this object. For example: IDataParameter param = databaseObjectSQL.GetNewParameterInstance();

By using the GetNewParameterInstance you are not hard coding the database specific parameter type, hence if you ever decide to move the underlying data store to a different data store (e.g. move from SQL Server to Oracle or vice versa), you will NOT need to recompile and the application will continue to work.  

Public PropertyUseTransaction

UseTransaction

Value of UseTransaction determines weather this object will create a Transaction at the time of creating database connection.

If UseTransaction is set to true, and AssignConnection method is used to create joined objects, the connection, transaction are automatically shared by each business object. This allows multiple business objects to run various commands under the same transaction scope.


myBusinessObj.UseTransaction = true;

NOTE: This property is set to false by default, and hence for the business object to run various commands in a transaction, this property must be explicitely set to true.

 
Top

Public Methods

 NameDescription
Public MethodAssignConnection

AssignConnection

If the current instance does not have an instance of database connection object, then this method calls CreateConnection method. After that the reference to the existing database connection object stored in DBConnection is passed to the passed in Object's DBConnection member variable.

If the current instance's UseTransaction is set to true then this method also passes the reference to the existing transaction object stored in DBTransaction to the passed in Object's DBTransaction member variable.

This method also assigns the SessionStartCommand and SessionEndCommands allowing any of the connected business objects to be able to run the SessionStartCommand and SessionEndCommand at the time of database connection opening and closing.

Parameters:
Description
dbObjDatabaseObjectSQL instances that will receive the DBConnection and DBTransaction values.


	this.AssignConnection(databaseObjectToJoin);
	
 
Public MethodCommitTransaction CommitTransaction

Commits the active SQL Transaction held in DBTransaction member variable, and then Disposes the transaction object, closes the connection object and sets it to null.

NOTE: This however does not affect your ability to run more commands to the underlying database using the same instance of the database object instance as the database object creates a new connection when trying to run a new command after the earlier connection has been closed.

 
Public MethodCreateConnection

CreateConnection

Creates a database connection and sets the DBConnection property.

Depending on the DBType value either a SqlConnection object is created and stored in DBConnection property or an OracleConnection object is created and stored. If the DBConnection already has a connection object then this method does not create a new instance, instead it simply ensures that the connection is open.

Also, if the UseTransaction property is set to true, then a new transaction object is created at the time of creating a connection.

If there are any exceptions during connection or transaction object creation, the ErrorString property is populated with the exception message.


	dbObj.CreateConnection();
	
 
Public MethodDispose Dispose

If the DBTransaction is not null, then this method permorms a RollBack on the active SQL Transaction held in DBTransaction member variable, and then Disposes the transaction object, closes the connection object and sets it to null.

Effective version 3.x this method has been marked virtual and hence can be overridden by any of the inheriting classes.

 
Public MethodGetNewParameterInstance

GetNewParameterInstance

Returns a new instance of parameter object that is suitable to be used with the currently selected DatabaseType.


		IDataParameter param =
        databaseObjectSQL.GetNewParameterInstance();
		param.Name = "myParamName";
	
 
Public MethodGetSQLExceptionAsStringGetSQLExceptionAsString

Gets detailed error message and the source of the passed in Exception.

Parameters:
Description
sqExException instance to use for returning an error message.
 

Public MethodRollBackTransactionRollBackTransaction

Performs a RollBack on the active SQL Transaction held in DBTransaction member variable, and then Disposes the transaction object, closes the connection object and sets it to null.

 
Public MethodRunSessionEndCommand

RunSessionEndCommand

Runs the command specified in the SessionEndCommand property. It is not necessary to call this method as the SessionEndCommand is automatically run when the database connection object is being disposed. This method is however provided for convenience in case you need to run this command several times in a session.

All parameters assigned to the SessionEndParameters are also used to provide parameters to the command as well.


	databaseObjectSQL.RunSessionEndCommand();
	
 
Public MethodRunSessionStartCommand

RunSessionStartCommand

Runs the command specified in the SessionStartCommand property. It is not necessary to call this method as the SessionStartCommand is automatically run when the database connection is opened. This method is however provided for convenience in case you need to run this command several times in a session.

All parameters assigned to the SessionStartParameters are also used to provide parameters to the command as well.


	databaseObjectSQL.RunSessionStartCommand();
	
 
Public MethodRunSPReturnDataReaderRunSPReturnDataReader

This method runs a Stored procedure and returns a data reader object

Parameters:
Description
procNameSQL Stored procdeure name to be executed.
parameterValuesAn array of objects to be assigned as the input values of the stored procedure.

Returns:
Type
IDataReader
 

Public MethodRunSPReturnDatasetOverloaded. RunSPReturnDataset

This method runs a Stored procedure and returns a dataset.

Parameters:
Description
procNameSQL Stored procdeure name to be executed.
parameterValuesAn array of objects to be assigned as the input values of the stored procedure.

Returns:
Type
System.Data.DataSet
 

Public MethodRunSPWithNoReturnOverloaded. RunSPWithNoReturn

This method runs a Stored procedure and does not return any result set

Parameters:
Description
procNameSQL Stored procdeure name to be executed.

Returns:
Type
System.Int32
 

Public MethodRunSQLReturnDatasetOverloaded. RunSQLReturnDataset

This method runs a SQL Command and returns a dataset.

Parameters:
Description
sqlCommandSQL command to be executed.

Returns:
Type
System.Data.DataSet
 

Public MethodRunSQLWithNoReturnOverloaded. RunSQLWithNoReturn

This method runs a SQL Command and returns the number of records affected.

Parameters:
Description
sqlCommandSQL command to be executed.

Returns:
Type
System.Int32
 

Public MethodSetDatabaseType

SetDatabaseType

Takes a String as the parameter and sets the DBType property with the type of database to which this object will be connecting.

Parameters:
Description
dBType

Sets the DBType property value with the value passed in.

Possible values for passing to this method are:

SqlServer2000

SqlServer2005

Oracle8i

Oracle9i

Oracle10g


myBusinessObj.SetDatabaseType("SqlServer2005");
(Inherited from DatabaseObject)
Public MethodSetSqlParamType SetSqlParamType - This method can be used to set the appropriate DBType property of the parameter.  
Top

Protected Methods

 NameDescription
Protected MethodEnsureConnectionStringEnsureConnectionString

Checks the ConnectionString property and if it is nont set, it will try to get the Configuration / AppSettings / key (1.1 Framework) or Configuration / ConnectionStrings / key (2.0 Framework) that defines the database connection String.

Calling this method is not needed in normal scenarios. This will be needed only if you are changing the ConnectionStringConfigName property through the code and would want to ensure that the new value is loaded from the configuration file and the ConnectionString property is updated accordingly.

If you are calling EnsureDatabaseType method as well then you don't need to do that as EnsureDatabaseType is called by the EnsureConnectionString. (Inherited from DatabaseObject)

Protected MethodEnsureDatabaseTypeEnsureDatabaseType

Checks the DBType property and if it is set to None, it will try to get the Configuration / AppSettings / key that defines the DBType.

Calling this method is not needed in normal scenarios. This will be needed only if you are changing the DatabaseTypeConfigName property through the code and would want to ensure that the new value is loaded from the configuration file and the DBType property is updated accordingly.

If you are calling EnsureConnectionString method as well then you don't need to call EnsureDatabaseType as it is called by the EnsureConnectionString. (Inherited from DatabaseObject)

Protected MethodGetNewAdapterInstanceGetNewAdapterInstance

GetNewAdapterInstance creates a new instance of IDbDataAdapter compatible data adapter depending on the type of connection object stored in DBConnection property.

If the DBConnection property holds an OracleConnection then a OracleDataAdapter is created, however if the DBConnection property holds an SqlConnection then a SqlDataAdapter is created.

The passed in command object is passed to the data adapter. The command object must match the connection type i.e. If the DBConnection is set to SqlConnection then an instance of SqlCommand must be passed.

In normal scenarios there will not be a need to call this method, but it is provided for situations where a complex query has to be run which is not supported directly by this library.

Parameters:
Description
commandPass either a SqlCommand or OracleCommand based on the type of connection set in DBConnection.

Returns:
Type
IDbDataAdapter
 

Top

See Also