Jump to content

ODBC / ADO AutoIt Questions


momitty
 Share

Recommended Posts

My most pressing problem is trying to get a list of schemas on a database. Anybody know how to do this?

I've collected code I've found around the forums and tried something like this, which connects okay but errors out :

$sqlCon = ObjCreate("ADODB.Connection")

$sqlCon.Mode = 16; shared
$sqlCon.CursorLocation = 3; client side cursor

; http://ns7.webmasters.com/caspdoc/html/syn...ion_strings.htm
; where [ip_address] is the IP address of the database server, [port_number] is the port for the database server,
; [database_name] is the name of the database,
; and [username] and [password] are the username and password required for accessing the database.
ConsoleWrite("start" & @CRLF);

$sqlCon.Open ("DSN=Database; UID=user; PWD=pass")
If @error Then
    MsgBox(0, "ERROR", "Failed to connect to the database")
    Exit
EndIf

ConsoleWrite("cxn opened" & @CRLF);
; See also Catalog "ADOX Catalog Example.au3"

$sqlRs = ObjCreate("ADODB.Recordset")
If Not @error Then
    $sqlRs = $sqlCon.OpenSchema('adSchemaCatalogs')
     ConsoleWrite("schemas read" & @CRLF);
    If Not @error Then
     ;Loop until the end of file
        While Not $sqlRs.EOF
         ;Retrieve data from the following fields
                $OptionName = $sqlRs.Fields ('TABLE_SCHEMA' ).Value
            $sqlRs.MoveNext 
        WEnd
        $sqlRs.close
    EndIf
EndIf

$sqlCon.Close

This next code chunk gets me a list of tables, but I can't get the schemas.

$adoxConn = ObjCreate("ADOX.Catalog")
$sqlCon = ObjCreate("ADODB.Connection")

$sqlCon.Open ("DSN=Database; UID=user; PWD=pass")
$adoxConn.activeConnection = $sqlCon 
    
$sqlCon.CursorLocation = 3; client side cursor


for $table in $adoxConn.tables
   ConsoleWrite($table.name & @CRLF)
next
Edited by momitty
Link to comment
Share on other sites

  • 2 weeks later...

I think if somebody knows how to convert this code this page I could make this work:

http://support.microsoft.com/kb/186246

Set rs = cn.OpenSchema(adSchemaIndexes, _
         Array(Empty, Empty, Empty, Empty, "Employees")

While Not rs.EOF
   Debug.Print rs!INDEX_NAME
   rs.MoveNext
Wend
There is more required than what you posted For example you did not open a data connection.

Go to

My Website and in the left menu ckick Code>>My Extra UDFs>>Access.au3. There are a few examples on that page to get you started. You can download the whole file in azip from the bottom of the page.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...