Hi all,

can I connect to a database (e. g. Oracle) and pass SQL commands from
my VBScript code? Where can I find information about this issue?

Jens

Re: SQL commands from VBScript? by ekkehard

ekkehard
Mon May 08 14:59:08 CDT 2006

Jens Lenge wrote:
> Hi all,
>
> can I connect to a database (e. g. Oracle) and pass SQL commands from
> my VBScript code?
yes
Where can I find information about this issue?
if you got some MDAC on your system, there should be a helpfile ado<NNN>.chm
somewhere
Google for something like "createobject("ADODB.Connection")"
look at http://msdn.microsoft.com/data/mdac/default.aspx

Re: SQL commands from VBScript? by Jens

Jens
Tue May 09 02:11:00 CDT 2006

Thanks - I will have a look.


Re: SQL commands from VBScript? by Richard

Richard
Tue May 09 11:25:52 CDT 2006


"Jens Lenge" <spampot@gmx.net> wrote in message
news:1147158660.048183.158160@y43g2000cwc.googlegroups.com...
> Thanks - I will have a look.
>

You need the syntax for a connection string for Oracle databases. See this
link:

http://www.connectionstrings.com/

You must assign your SQL statement to a string variable, which involves
enclosing it in quotes. The trick is to get the commas, spaces, and quotes
correct in the string. The code could be similar to below (I don't have an
Oracle db so I cannot test):

Option Explicit
Dim strConnnect, adoRecordset, strField1, strField2

' Connection string for Oracle database.
strConnect = "Driver={Microsoft ODBC for Oracle};" _
& "Server=OracleServer.world;" _
& "Uid=Username;" _
& "Pwd=asdasd;"

Set adoRecordset = CreateObject("ADODB.Recordset")
adoRecordset.ActiveConnection = strConnect
adoRecordset.Source = "SELECT Field1, Field2 " _
& "FROM MyTable " _
& "WHERE Field3 = 'Error'"
adoRecordset.Open

Do Until adoRecordset.EOF
strField1 = adoRecordset.Fields("Field1").Value
strField2 = adoRecordset.Fields("Field2").Value
Wscript.Echo strField1 & ", " & strField2
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close

You can also use a Connection object. If I am modifying data, I use a
Command object. See ADO documentation for more.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: SQL commands from VBScript? by Jens

Jens
Wed May 10 11:32:39 CDT 2006

Great hint!
Thank you very much!