In this recipe, we will show how to establish a DB connection using VBScript code. We will build a simple custom class, DB_Handler
that will be instantiated using a global scope variable, oDBHandler
. This global object will serve as the basis for all our DB operations.
From the File menu, navigate to New | Function Library... or use the Alt + Shift + N shortcut. Name the new function library DB_Func.vbs
.
The following code handles creating, opening, and closing a DB connection using ADODB
:
Const C_ADODB_OBJ = "ADODB.Connection" Dim oDBHandler Function createDBHandler(p, ds, ic, uid, pwd) On error resume next Set oDBHandler=new DB_Handler call oDBHandler.Init(p, ds, ic, uid, pwd) createDBHandler=eval("err.number=0") End Function Class DB_Handler private m_oDBConnection Public Provider Public DataSource Public InitialCatalog Public Username Public Password ...