Программирование в IIS

Пример 1.4

IObjectConstruct_Construct event subroutine implementation in clsClass Option Explicit Implements IObjectConstruct

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ***** constants to class ***** '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'old style connection string in case nothing else works Private Const DEFAULT_CONSTRUCTION_STRING = _ "driver={Microsoft Access Driver (*.mdb)};" & _ "dbq=D:\aspData\employees.mdb"

Private Const DEFAULT_COLOR = "Brown" Private Const CHAIR_ID = "ID" Private Const CHAIR_COLOR = "Color"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' ***** locals to class ***** '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'holds the color of the chair Private m_scolor As String

'Chair ID for class instance Private m_sID As String

'holds the ADO Connection to the data 'source that the object interacts with Private m_Connection As ADODB.Connection

Private m_sErrorMessage As String

Private Sub IObjectConstruct_Construct(ByVal pCtorObj As Object)

On Error GoTo Sub_Error_Handler Const ERROR_MESSAGE_INFO = "IObjectConstruct_Construct"

Dim sConnection As String

sConnection = pCtorObj.ConstructString

'make certain there is something If Len(sConnection) < 1 Then sConnection = DEFAULT_CONSTRUCTION_STRING End If

'establish connection to database server If m_Connection Is Nothing Then Set m_Connection = CreateObject("ADODB.Connection") End If

m_Connection.Open sConnection 'DEFAULT_CONSTRUCTION_STRING 'establish connection to database server Set m_Connection = CreateObject("ADODB.Connection") m_Connection.Open sConnection '"DSN=ASPExample"

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ sub_Exit_Done: Exit Sub

Sub_Error_Handler: 'record the error in class instance and rethrow 'for consuming software to learn of issue ProcessErr ERROR_MESSAGE_INFO & _ " Failure obtaining database connection information." & _ " Class will not connect to database" End Sub

Листинг 1.4.

Закрыть окно

Содержание  Назад  Вперед