New in PrimalScript 2007: ADO Database Wizard

A common task for scripters is working with databases. Typically VBScript coders use ADO to access database tables. However, creating code to access, modify or otherwise interact with databases can be arcane and mystifying. The Professional and Enterprise editions of PrimalScript 2007 include an ADO Wizard that generates VBScript code.

adowizard-generatecode.png

Using a database connection from the Database Browser, right-click the table you want to work with and select Generate VBScript Code.

adowizard-settings.png

The Wizard automatically generates the connection string. You can adjust the settings to control what type of code is generated.

Here’s my wizard generated code that only took me a few mouse clicks:

On Error Resume Next
‘Database connection
Dim objCn
Set objCn = CreateObject(“ADODB.Connection”)
objCn.Open “Provider=SQLOLEDB.1;Integrated Security=SSPI;” &_
Persist Security Info=False;Initial Catalog=JDHDB;” &_
“Data Source=godot\sqlexpress”

‘Query data
Const ADO_Dynamic = 2
Const ADO_FwdOnly = 0
Const ADO_Keyset = 1
Const ADO_Static = 3

Dim rs_Computers, strSQL
strSQL = “Select * from Computers”

Set rs_Computers = CreateObject(“ADODB.RecordSet”)
rs_Computers.Open strSQL, objCn, ADO_FwdOnly

‘Go through data
Do Until rs_Computers.EOF
    WScript.Echo rs_Computers(“Name”)
    WScript.Echo rs_Computers(“AssetTag”)
    WScript.Echo rs_Computers(“Updated”)
    rs_Computers.MoveNext
Loop
‘Close database connections
rs_Computers.Close
objCn.Close
On Error GoTo 0

I can insert this into my open VBScript, and I’m done! Now you can create database scripts in fraction of the time. The wizard will also let you create custom class objects to make it easier to update or insert new data. It will even generate some sample code to give you a guideline on how to use the classes.

You can try out the ADO wizard and other new features by downloading a 45 day evaluation copy of PrimalScript 2007.