FR 
 
Site navigation



User Management Resource Administrator: User Account Management for Windows 2003/XP/2000/NT

Previous Topic

Next Topic

Book Contents

ADO database connection - OLE DB provider

The first section of the script is used to setup a connection with the database. In this script, the Microsoft ADO (ActiveX Data Objects) standard is used to access the database. This is a very common technique used in VBScript to access a database. With ADO, the data is accessed using the OLE DB provider. Almost all database types can be accessed using OLE DB (including ODBC connections) so this method can be used for almost all databases.

Dim adoConn, adoRS

Set adoConn = CreateObject("ADODB.Connection")

Set adoRS = CreateObject("ADODB.Recordset")

adoConn.Provider = "Microsoft.Jet.OLEDB.4.0"

adoConn.Open "FirstLastNames.mdb"

Set adoRS.ActiveConnection = adoConn

adoRS.Open "SELECT * FROM FirstLastNamesTable"

Two script variables are initialized: the connection (adoConn) and the record set (adoRS). With the CreateObject function, the ADODB COM objects ADODB.Connection and ADODB.RecordSet are created. The CreateObject function creates an instance of the specified COM object. So this is also COM, not UMRA COM but ADO COM.

Next, the Provider of the connection object is set to Microsoft.Jet.OLEDB.4.0. The provider member specifies the type of the database connection. For a different database, this provider specification differs. The database is opened with the Open method of the ADODB.Connection object. The name of the database file, FirstLastNames.mdb is specified as the argument of the call.

With the statement Set adoRS.ActiveConnection = adoConn the recordset object is initialized. The Open method of the ADODB.Recordset is then used to perform a query in the database: SELECT * FROM FirstLastNamesTable: All records from the table are returned and can be accessed through the recordset object.

See Also

Script section: Setting up the database connection


Home | Products | Support | Pricing | Download | Press | About Us | Contact | Sitemap
QUICK LINKS: Mass / Bulk Import Software | Network Monitoring Software | Disk Quota Management
QUICK LINKS: User and Active Directory Management | Active Directory Migration | SSRPM Documentation