Thanks Shalabh!!!

On Wed, Aug 31, 2011 at 1:06 AM, Shalabh Dixit <[email protected]>wrote:

> Sain,
>
> You can use the code below... I have created a generic Database utility
> library for day to day operations on database below are some sample
> functions from the same.
>
>
> ''========================================================================================
> '(1.) Function to Connect to the Database
>
> ''========================================================================================
> Function ConnectDatabase(Byval strConName,Byval strDSNName,Byval
> strServerName,Byval strDataBaseName,Byval strUserID,Byval strPassword)
>     'Assign Database Connection Information to the DB Variables
>     DataSource = strDSNName
>     Server = strServerName
>     UserID_DB = strUserID
>     Password_DB = strPassword
>     DatabaseName_DB = strDataBaseName
>     con=strConName
>     Dim connItems(2)
>     Dim connState
>     'Declare Database Recordset variable
>     conString =
> cstr("DSN="&DataSource&chr(59)&"Server="&Server&chr(59)&"UID="&UserID_DB&chr(59)&"Password="&Password_DB&chr(59)&"DATABASE="&DatabaseName_DB)
>
>     'Create Database Connection Object
>     Set conn = CreateObject("Adodb.Connection")
>
>     'Open Database Connection
>     conn.Open conString
>     'Verify the Successful Database Connection Establishment
>     If conn.State=1 Then
>         Reporter.ReportEvent micPass,"Database Connection Success","
> Database connection for "&DatabaseName_DB &"Database has been established
> Successfully"
>         'MsgBox "Connection Estblished Successfully"
>     Else
>         Reporter.ReportEvent micFail,"Database Connection Failure","
> Database connection for "&DatabaseName_DB &"Database is not been established
> successfully"
>         'MsgBox "Connection Not Estblished"
>     End If
>     connItems(0) = conn.State
>     connItems(1) = conn
>     ConnectDatabase = connItems
> End Function
>
> '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>
> ''========================================================================================
> '(2.) Function to Execute Any SQL Query
>
> ''========================================================================================
> Function ExecuteSQLQuery(ByVal DBConnectionState,ByVal
> DBConnectionProperty,Query)
>     If DBConnectionState = 1 Then
>         Set rst = createobject("adodb.recordset")
>         rst.Open Query,DBConnectionProperty
>         index = 0
>         Dim arrResultSet()
>         While rst.EOF <> True
>             ReDim Preserve arrResultSet(index)
>             arrResultSet(index) = rst.Fields(0).Value
>             rst.MoveNext
>             index = index + 1
>         Wend
>     End If
>     ExecuteQuery = arrResultSet
> End Function
>
> '----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>
> Regards
> Shalabh Dixit
>
>
>
> On Wed, Aug 31, 2011 at 12:47 AM, Anish Pillai <
> [email protected]> wrote:
>
>> Hi Sain,
>>
>> To make your object global, you can declare/define it in your function
>> library. That way all the test cases that you associate with your function
>> library will have access to the object.
>>
>> But what I personally feel is that DB connections should not be kept open
>> for longer durations. Its better to close the connections as soon as your
>> work is done. One can always reopen the connection whenever they want. But
>> I'm not sure how other people think about this point.
>>
>> Hope this helps..
>>
>> --
>> Regards,
>> Anish Pillai
>> My QTP Blog <http://automationrepository.blogspot.com>
>>
>>  --
>> You received this message because you are subscribed to the Google
>> "QTP - HP Quick Test Professional - Automated Software Testing"
>> group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/MercuryQTP?hl=en
>>
>
>  --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en

-- 
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en

Reply via email to