How to open a password-protected database.
Example:
Dim FlightNumber
Dim dbexample
‘ Create the conection object.
Set dbexample = CreateObject(“ADODB.Connection”)
‘Set the connection string and open the connection
dbexample.ConnectionString = “DBQ=D:\Program Files\Mercury Interactive\WinRunner\samples\flight\app\flight32.mdb;DefaultDir=D:\Program Files\Mercury Interactive\WinRunner\samples\flight\app;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;”
dbexample.Open
‘or use this method if a DSN entry was created.
‘dbexample.Open(“DSN=Flight32”)
flightnumber = 6195
‘ Get the recordset returned from a select query.
Set recordset = dbexample.Execute(“SELECT * from Orders WHERE Flight_Number = ” & flightnumber)
‘ Display the results of the query.
msgbox recordset.GetString
‘ Close the database connection.
dbexample.Close
Set dbexample = Nothing
If your query returns several columns, you can use the Fields method to retrieve data from specified columns in the returned record set.
Example:
‘ Connect to the Flight32 database
Set dbexample = CreateObject(“ADODB.Connection”)
dbexample.Open(“DSN=Flight32”)
‘ Perform a query
Set recordset = dbexample.Execute(“SELECT * from Orders”)
‘ Get the values from the Customer_Name column
while (NOT recordset.EOF)
MsgBox recordset.Fields(“Customer_Name”)
‘ Move to the next value in the record set
recordset.MoveNext
wend
‘ Close the database connection.
dbexample.Close
Set dbexample = Nothing