Thursday, December 7, 2006

vbscript to access oracle database

Thursday, December 07, 2006 Posted by Andre Broers
'The connection string
sConnectionString = "Provider=MSDAORA;Data

Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=<hostname>)(Port=1521)))(CONNECT_DATA=(SID=<sid>)));UserID=<username>;Password=<password>"

'The connection (vbscript):
Set connection = WScript.CreateObject("ADODB.Connection")
connection.ConnectionString = sConnectionString
connection.Open
if Err.Number <> 0 Then
WScript.Echo Err.Number
WScript.Echo Err.Description
WScript.Quit
Else
WScript.Echo "Connected to the database "+ connection.provider
End If

Set rs = CreateObject("ADODB.recordset")
strSQL = "SELECT tablename FROM all_tables"
rs.open strSQL, connection, 3,3

rs.MoveFirst
WHILE NOT rs.EOF
wscript.echo (rs("tablename") & "<br/>")
rs.MoveNext
WEND