How to Connect to the Database in VBS

How to Connect to the Database in VBS thumbnail
Many websites reference databases via scripting languages.

VBScript is a light version of the Microsoft Visual Basic programming language. VBScript must be executed within a hosting environment such as Internet Explorer, Windows Scripting Host or Internet Information Services. The VBScript can also be embedded in another application by using Microsoft Script Control. Software testers will often use VBScript to automate testing. VBScript is lightweight and easy to use but still capable of executing somewhat complex tasks such as database interactions.

Instructions

    • 1

      Open a text editor such as Notepad.exe and begin writing your VBScript. Declare the variable to be used within your script first. You will need to define variables for the cursor type, lock type and cursor location.

    • 2

      Create the connection object and a recordset object. The connection object is needed to connect to the database. Use "CreateObject("ADODB.Connection")" to define a new connection object.

    • 3

      Open the database by referencing the connection object name (i.e., myConn), followed by ".Open" and the database source name (DSN). The DSN will contain information to the ADODB driver that is specific to the particular database.

    • 4

      Open a recordset by referencing the recordset object (i.e., myRecordSet), followed by ".Open." The "open" statement of the recordset requires a SQL statement, the connection object, the cursor type and the lock type. You will get an error if you attempt to open a recordset before opening the connection.

    • 5

      Close the database connection at the end of your script. The ".Close" command is used for both recordset and connection objects.

Related Searches:

References

  • Photo Credit John Foxx/Stockbyte/Getty Images

Comments

You May Also Like

Related Ads

Featured