Jump to content
Sign in to follow this  

SQL Connection

Recommended Posts


Hi All,

Does anyone know if autoit scripting can be used to connect to a database and run a query?

Assuming that I have the username, password and the database driver.


Share this post

Link to post
Share on other sites

I ssaw that before, if you are mentioning _SQLite_

but it seems to me that its some internal database that autoit uses. Please correct me if I am wrong.

I want to connect to an Oracle DB and run a query? Is that possible?

Share this post

Link to post
Share on other sites


This is an example on how to connect and run a QRY on an Oracle DB.

#include <GUIConstants.au3>

Dim $oMyError

; Initializes COM handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$ado = ObjCreate( "ADODB.Connection" )  

With $ado
    .ConnectionString =("Provider='OraOLEDB.Oracle';Data Source='YourTNS_Name';User Id='system';Password='YourPswd';") 

$adors = ObjCreate( "ADODB.RecordSet" )   

With $adors
        .ActiveConnection = $ado
        ;.CursorLocation = "adUseClient"
        ;.LockType = "adLockReadOnly" ; Set ODBC connection read only
        .Source = "select * from db.test"

While not $adors.EOF
    For $i = 0 To $adors.Fields.Count - 1
    ConsoleWrite( $adors.Fields( $i ).Value & @TAB )    ; Columns in the AutoIt console use Column Name or Index
    $adors.MoveNext                                                ; Go to the next record

; This is Sven P's custom error handler added by ptrex
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
  SetError(1)  ; to check for after this function returns



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.