Hi All.
Win 2kpro, sql server 2k, iis5 vbscript asp
Learning vbscript
I was wondering if anyone could help me with a VBscript CLASS I have
that I use for connecting to our database and execute stored procs.
I've included my CLASS to this message. Could someone please take a
look at it and possibly correct & alter it to make it better.
One bit I would like added is to beable to RETURN a value from a
Stored Procedure rather than a recordset using the class. I've tried
to comment it as much & clear as I can.
If anyone has any useful vbscript CLASS code that they wouldn't mind
sharing - I'd appreciate it.
Thanks for all the help & tips in advance.
Al
<%
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| Class : clsDBErrorChecker
|
'| Language : VBscript
|
'| Description : Used for checking DB for errors & Executing SQLs
|
'| Copyright : (c) 2003 Alan Spencer (Harag)
|
'|---------------------------------------------------------------------------------------------------------------------|
'| Properties : TotalErrors (read)
|
'| : AnyErrors (read)
|
'| : ExtraInfo (Write)
|
'| : InFunction (write)
|
'| : ConnectAs (write)
|
'|---------------------------------------------------------------------------------------------------------------------|
'| Methods : OpenDBConnection
|
'| : CloseDBConnection
|
'| : BeginTrans
|
'| : CommitTrans
|
'| : RollbackTrans
|
'| : Execute (sql, ReturnRS? T/F)
|
'| : OpenRS (sql, cursortype, locktype, options)
|
'| : OpenIntoArray (sql, Rows,Start,Array(fileds))
|
'| : ClearErrors
|
'| : GetFullError(x)
|
'| : GetAllFullErrors
|
'| : GetUserDefinedError
|
'| : SetInfo
|
'| : ResetInfo
|
'|---------------------------------------------------------------------------------------------------------------------|
'| Private : (S) ReportConnectionClosed
|
'| : (F) IsConnectionOpen
|
'| : (S) UpdateConnectionString
|
'|______________________________________________________________________________|
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| Options : adCmdText, adCmdStoredProc, adExecuteNoRecords
|
'|______________________________________________________________________________|
'| EXAMPLE OF USAGE (copy the text below and uncomment all the first
rem) |
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
' In Global.asa file:
' ***user*** & ***pass*** are altered via the DBclass
' Application("sDBConnection") = "Provider=SQLOLEDB; Data
Source=(local); Initial Catalog=dbnamehere; User ID=[***USER***];
Password=[***PASS***]; Persist Security Info=True"
'
---------------------------------------------------------------------------------------------------------------------
'
' 'Declare class
' DIM clsDBCheck, oRSfoobar
' set clsDBCheck = new clsDBErrorChecker
' ' Set the connection username
' clsDBCheck.ConnectAs = CONNECTAS_VSUser '
CONNECTAS_VSUser is the default
'
' ' Setup info code incase of error
' clsDBCheck.SetInfo "YourFunctionName", "Some info for finding
line in code easier. eg a linenumber or section header"
' ' create SQL string
' sSQL="usp_TEST_DisplaySecurityLevelUsers 16"
'
' ' run SQL string
' set oRSfoobar = clsDBCheck.OpenRS (sSQL, adOpenKeySet,
adLockPessimistic)
' ' ***OR ***
' set oRSfoobar = clsDBCheck.Execute (sSQL, true) '
return records
' ' ***OR ***
' clsDBCheck.Execute (sSQL, false) ' return no records
' ' ***OR ***
' MyArray = clsDBCheck.OpenIntoArray (sSQL, 0, 0, "")
'
' ' if any errors then report the errors else do stuff with
record set.
' if clsDBCheck.AnyErrors then
' Out clsDBCheck.GetAllFullErrors
' else
' ' SQL ran with no errors.
' if not oRSfoobar.BOF and not oRSfoobar.EOF then
' do
' ' Do some stuff here
' oRSfoobar.MoveNext
' loop until oRSfoobar.EOF
' end if
' oRSfoobar.Close
' end if
'
' ' Finally close & free memory
' clsDBCheck.CloseDBConnection
' set clsDBCheck = nothing
'_______________________________________________________________________________
'|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| S T A R T O F T H E C
L A S S
|
'|______________________________________________________________________________|
CONST NO_EXTRA_INFO = "<B><I>***None***</B></I>" ' default
extra info text (const)
CONST IN_FUNCTION = "<B><I>***Main***</B></I>" '
default function text (const)
' these are for DB security to connect using different login names
CONST CONNECTAS_User =1
CONST CONNECTAS_Admin =2
CONST CONNECTAS_Executive =3
CONST CONNECTAS_MAX=3
CLASS clsDBErrorChecker
'_____________________________________
'| Declare some PRIVATE variables for the class |
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
PRIVATE msConnString ' String
holding the actual Connection info
PRIVATE moConnection ' Connect
object to the DB - ADODB.Connection
PRIVATE mbIsConnectionOpen ' Boolean True if connetted to
DB
PRIVATE miConnectAs '
Username/password ID for connecting to DB
PRIVATE maConnectAsArray(3,1) ' Array of users &
Passwords
PRIVATE msExecutedSQL ' The executed SQL
PRIVATE msExtraInfo '
Extra info for the error results
PRIVATE msInFunction ' stores the
function name set for error results
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| I N I T I A L I Z E F U N C T I O N S
|
'|______________________________________________________________________________|
' Initialize the class, set up default variables erc.
PRIVATE SUB Class_Initialize
msExtraInfo = NO_EXTRA_INFO
msInFunction = IN_FUNCTION
mbIsConnectionOpen=false
' set the default user to connect as (public)
miConnectAs= CONNECTAS_User
' load all the username & passwords into an array
maConnectAsArray (CONNECTAS_User, 0) =
"publicusernamehere"
maConnectAsArray (CONNECTAS_User, 1) =
"userpasswordhere"
maConnectAsArray (CONNECTAS_Admin, 0) =
"siteadminusername"
maConnectAsArray (CONNECTAS_Admin, 1) =
"adminpassword"
maConnectAsArray (CONNECTAS_Executive, 0) =
"dbousernamehere"
maConnectAsArray (CONNECTAS_Executive, 1) =
"executivepasswordhere"
UpdateConnectionString
' Create The connection Object for the class
set moConnection = Server.CreateObject
("ADODB.Connection")
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' When class is terminated also terminate the connection to
the DB to free up resources
PRIVATE SUB Class_Terminate
' Close the connection Object and clear it
CloseDBConnection
set moConnection=nothing
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| P R O P E R T I E S
|
'|______________________________________________________________________________|
' will return 0 if none or >0 if there is any.
PUBLIC Property get AnyErrors
if TotalErrors >0 then
AnyErrors=true
else
AnyErrors=false
end if
End Property
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' returns the number of DB errors
' If warnings then reduces the number.
' eg "Cursor Type Changed"
PUBLIC Property get TotalErrors
DIM TotErr, NatErr, x, xx
TotErr = moConnection.Errors.Count
if TotErr > 0 then
xx = TotErr - 1
for x = 0 to xx
NatErr =
moConnection.Errors.Item(x).NativeError
if NatErr = 0 then
TotErr = TotErr - 1
end if
Next
end if
TotalErrors=TotErr
End Property
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' changes the connection string to a new username & password
as some Stored procs have
' different permissions from "public"
PUBLIC Property let ConnectAs (ByVal iNewConnect)
if iNewConnect <1 or iNewConnect > CONNECTAS_MAX then
iNewConnect = CONNECTAS_user
end if
' if changing to a new connect user then close DB and
reset ConnectionStr
if miConnectAs <> iNewConnect then
miConnectAs =iNewConnect
UpdateConnectionString
CloseDBConnection
end if
End Property
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' stores a string incase error is found and displayed, put
handy info to find line in code
PUBLIC Property let ExtraInfo (ByVal sInfo)
sInfo=trim(sInfo)
if sInfo="" then
msExtraInfo = NO_EXTRA_INFO
else
msExtraInfo = sInfo
end if
End Property
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' If Executing a SQL/stored proc in a FUNCTION then set this
to the FUNCTION name for ease of finding error
PUBLIC Property let InFunction (ByVal sInfo)
sInfo = trim(sInfo)
if sInfo = "" then
msInFunction = IN_FUNCTION
else
msInFunction = sInfo
end if
End Property
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| F U N C T I O N S / S U B S
|
'|______________________________________________________________________________|
' Opens up a connection to the DB - String must be valid
connection str.
'eg: "Provider=SQLOLEDB; Data Source=ServerName; Initial
Catalog=DBName; User ID=UserName; Password=UserPassowrd; Persist
Security Info=True"
' this string is altered using the "connectAs system"
PUBLIC SUB OpenDBConnection(ByVal sConnectionString)
moConnection.Open sConnectionString
mbIsConnectionOpen = true
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' Closes a connection to the DB
PUBLIC SUB CloseDBConnection ()
if mbIsConnectionOpen then
moConnection.Close
mbIsConnectionOpen = false
end if
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' Begin a DB transaction
PUBLIC SUB BeginTrans()
if IsConnectionOpen then
moConnection.BeginTrans
end if
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' Commit the transaction
PUBLIC SUB CommitTrans()
if IsConnectionOpen then
moConnection.CommitTrans
End if
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' Rollback the DB transaction
PUBLIC SUB RollbackTrans()
if IsConnectionOpen then
moConnection.RollbackTrans
End if
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' Execute a SQL/storedproc on the DB
' NOTE: returns with a CursorType of FORWARD_ONLY - if you
want a different cursor type then
' use the "OpenRS" function
PUBLIC FUNCTION Execute (ByVal sSQL, ByVal bReturnRS)
DIM rs, lOptions
lOptions = adCmdUnknown
if IsConnectionOpen then
if not bReturnRS then
lOptions = lOptions+adExecuteNoRecords
end if
msExecutedSQL=sSQL
on error resume next
set rs = moConnection.execute
(msExecutedSQL, ,lOptions)
on error goto 0
if TotalErrors>0 then
if not lOptions AND adExecuteNoRecords
then
set Execute =
Server.CreateObject ("ADODB.Recordset")
end if
else
if not lOptions AND adExecuteNoRecords
then
set Execute=rs
end if
end if
end if
set rs=nothing
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' set oRSfoobar = clsDBCheck.OpenRS (sSQL, adOpenKeySet,
adLockPessimistic)
' CursorType, LockType, Options
' Allows you to set a cursor type to override executes default
PUBLIC FUNCTION OpenRS (ByVal sSQL, ByVal iCursorType, ByVal
iLockType)
' adOpenKeySet, adLockPessimistic
DIM rs
if IsConnectionOpen then
set rs=Server.CreateObject ("ADODB.Recordset")
rs.CursorLocation=adUseClient
msExecutedSQL=sSQL
on error resume next
rs.Open msExecutedSQL, moConnection,
iCursorType, iLockType
on error goto 0
if TotalErrors>0 then
set OpenRS = Server.CreateObject
("ADODB.Recordset")
else
set OpenRS=rs
end if
end if
set rs=nothing
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' Run an SQL/StoredProc and load the recordset into an array.
PUBLIC FUNCTION OpenIntoArray (ByVal sSQL, iRows, iStart,
aFieldsArray)
DIM rs
if IsConnectionOpen then
if iRows=0 then iRows=adGetRowsRest ' get
all rows
if iStart=0 then iStart=adBookmarkfirst '
start at the begining
msExecutedSQL=sSQL
set rs= OpenRS (msExecutedSQL, adOpenStatic,
adLockPessimistic)
if TotalErrors>0 then
OpenIntoArray = "" ' return a
string so user can check for (IsArray)
else
if not rs.BOF and not rs.EOF then
if IsArray(aFieldsArray) then
OpenIntoArray =
rs.getrows(iRows, iStart, aFieldsArray)
else
OpenIntoArray =
rs.getrows(iRows, iStart)
end if
else
OpenIntoArray=null
end if
end if
end if
set rs=nothing
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' clear the errors if your want... not really needed
PUBLIC SUB ClearErrors
moConnection.Errors.clear
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' returns a string of ONE error in an HTML format.
PUBLIC FUNCTION GetFullError(ByVal iErr)
DIM Tot, sTemp, En, errErrors
' 3621 = The statement has been terminated
Tot=TotalErrors
set errErrors = moConnection.Errors.Item(iErr)
if Tot>0 and iErr>=0 and iErr<=Tot-1 then
sTemp=""
En=errErrors.NativeError
if en <50000 then
if en <> 3621 then
sTemp=sTemp & "<P
STYLE=""text-align:left""><SPAN STYLE=""color:#990000""><B>DB
ERROR:</B></SPAN> <B>[File: </B>"&Request.ServerVariables
("SCRIPT_NAME")&"<B>]</B> "
sTemp=sTemp &
"<BR><B>[User:</B>"&maConnectAsArray (miConnectAs, 0)
&"<B>]</B><B>[Func: </B>"&msInFunction&"<B>]</B><B>[xInfo:
</B>"&msExtraInfo&"<B>]</B>"
sTemp=sTemp & "<BR><B>[ERR
SRC: </B>" & errErrors.source &"<B>]</B>"
sTemp=sTemp &
"<BR><B>[NativeError: </B>" & errErrors.NativeError &"<B>]</B> <B>[Err
Number: </B>"&errErrors.number & "<B>]</B> <B>[SQLstate:
</B>"&errErrors.SQLState & "<B>]</B>"
sTemp=sTemp & "<BR><B>[Desc:
</B>"& errErrors.Description&"<B>]</B>"
sTemp=sTemp & "<BR><B>[SQL:
</B>"&msExecutedSQL&"<B>]</B>"
end if
else
sTemp=GetUserDefinedError
end if
end if
set errErrors = nothing
GetFullError=sTemp
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' returns a string of all the errors found in HTML format.
PUBLIC FUNCTION GetAllFullErrors
DIM tot, x, sTemp
Tot=TotalErrors
sTemp=""
if tot>0 then
for x = 0 to Tot-1
sTemp=sTemp & GetFullError(x)
next
end if
GetAllFullErrors=sTemp
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' if use "RAISERROR ("some text",16,1) in an SQL Stored Proc
then this will return just the
' "Some Text" part of the error to a string.
PUBLIC FUNCTION GetUserDefinedError
DIM tot, x, sTemp
Tot=TotalErrors
sTemp=""
if Tot>0 then
for x = 0 to Tot-1
if
moConnection.Errors.Item(x).NativeError >=50000 then
sTemp=sTemp &
"<BR><B>[NativeError: </B>" & moConnection.Errors.Item(x).NativeError
&"<B>]</B>"
sTemp=sTemp &"<B>[ERROR:
</B>"& moConnection.Errors.Item(x).Description&"<B>] </B>"
'sTemp=sTemp &"<B>[ERROR:
</B>"& mid(moConnection.Errors.Item(x).Description,
InstrRev(moConnection.Errors.Item(x).Description,"[SQL
Server]")+12)&"<B>] </B>"
end if
next
end if
GetUserDefinedError=sTemp
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' A Quick way to set the ExtraInfo & InFunction parameters.
PUBLIC SUB SetInfo (ByVal sWhatFunction, ByVal sWhatInfo)
InFunction = sWhatFunction
ExtraInfo =sWhatInfo
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' This resets the ExtraInfo & InFunction strings to the
default values.
' Best place to run this is at the end of a function/sub
PUBLIC SUB ResetInfo
ExtraInfo =""
InFunction = ""
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| ***P R I V A T E*** F U N C T I O N S /
S U B S
|
'|______________________________________________________________________________|
' If connection is closed then see if there is an application
connection string
' if so open a connection automatically
PRIVATE FUNCTION IsConnectionOpen
if not mbIsConnectionOpen then
if not IsEmpty(msConnString) then
OpenDBConnection msConnString
else
ReportConnectionClosed
end if
end if
IsConnectionOpen = mbIsConnectionOpen
END FUNCTION
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
' If connection is closed then report error.
PRIVATE SUB ReportConnectionClosed()
DIM sTemp
sTemp= "<P STYLE=""text-align:left""><SPAN
STYLE=""color:#990000""><B>DB ERROR:</B></SPAN> <B>[File:
</B>"&Request.ServerVariables ("SCRIPT_NAME")&"<B>]</B> "
sTemp=sTemp & "<BR><B>[Func:
</B>"&msInFunction&"</B>]</> <B>[xInfo: </B>"&msExtraInfo&"<B>]</B>"
sTemp=sTemp & "<BR><B>[Desc: </B>THE DB CONNECTION HAS
NOT BEEN OPENED!!!!<B>]</B>"
sTemp=sTemp & "<P>You need the following 2 lines when
accessing the DB:"
sTemp=sTemp & "<BR>set g_clsDBCheck = new
clsDBErrorChecker"
sTemp=sTemp & "<BR>Application(""sDBConnection"")=
""Your Connection string here"" "
sTemp=sTemp & "<BR><BR>Eg ""Provider=SQLOLEDB; Data
Source=ServerIP; Initial Catalog=DBname; User ID=Username;
Password=password; Persist Security Info=True"""
Response.Write sTemp
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
PRIVATE SUB UpdateConnectionString()
msConnString=Application("sDBConnection")
msConnString = replace (msConnString, "[***USER***]",
maConnectAsArray(miConnectAs,0))
msConnString = replace (msConnString, "[***PASS***]",
maConnectAsArray(miConnectAs,1))
END SUB
'|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
'| E N D O F T H E C L A
S S
|
'|______________________________________________________________________________|
END CLASS
%>