Friday, July 6, 2007

Connecting to Database

//** this function is used to establis Database connection by sending connection string value.

strConnectionString value should look like DSN=dbAppl;NA=testing,3219;DB=appl_int1;UID=arun;PWD=arun

Public Function fnDBOpenConnection(strConnectionString)
fnDBOpenConnection=false

'Set the ADODB connection
Set dBConnection = CreateObject("ADODB.Connection")

'Verify for the object existance
If isobject(dBConnection) Then

'Set the connectionstring
dBConnection.ConnectionString = strConnectionString
dBConnection.Provider="MSDASQL.1"

'Open connections
On error resume next
dBConnection.Open(strConnectionString)

'Check for the error number
If not err.number = 0 then
'fnInsertResult "Database Verification", "Verifying the connection with Database", "Error in either connection string", "WARNING"
Reporter.ReportEvent micWarining, "Verifying the connection with Database", "Error in either connection string"
fnDBOpenConnection=false
Exit function
End If
On error goto 0
'fnInsertResult "Database connection", "Verifying the Database connection status ", "Database connection is opened", "PASS"
Reporter.ReportEvent micPass, "Verifying the Database connection status", "Database connection is opened"

'return the connections object back
Set fnDBOpenConnection = dBConnection
Else
'fnInsertResult "Database connection", "Verifying the Database connection status ", "Database connection is not opened", "WARNING"
Reporter.ReportEvent micWarning, "Verifying the Database connection status", "Database connection is not opened"
End If

'reinitialize the object property
Set dBConnection = Nothing

End Function

No comments: