Sign in to follow this  
Followers 0
The_Lorax

_SQLOpen() works but

5 posts in this topic

#1 ·  Posted (edited)

Hello all,

I'm fairly new to autoIT, and I've been trying to add a new record to a table in my database using the following code that I adapted from http://www.autoitscript.com/forum/index.ph...310&hl=_Sqlopen

Dim $oDBid,
$oDBid=_SQLOpen()              ; open database or _SQLopen("DRIVER={SQL Server}")
_SQLQuery($oDBid, "INSERT INTO Tbl_Client (LastName,FirstName) VALUES ('Smith','John)"); send query
SQLclose($oDBid)                                  ; close connection

I have to point the program to my .mdb file to get it to work. When I replace _SQLOpen() with _SQLOpen("c:\database.mdb") the _SQLOpen() function crashes on line 41 during execution, with the error:

C:\Program Files\AutoIt3\Include\SQL.au3 (41) : ==> The requested action with this object has failed.

Line 41 of SQL.au3 is:

$o_ADOcn.Open ($s_DSN)

I assume I've passed _SQLOpen() an incorrectly formatted path. Does anyone know what i've done wrong?

Thanks in advance.

Edited by The_Lorax

Share this post


Link to post
Share on other sites



just fixed my problem for doing a little more reading! ;)

followed a link to connectionstrings.com and tried this:

Dim $oDBid,
$oDBid=_SQLOpen("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\database.mdb;Uid=Admin;Pwd=;")
_SQLQuery($oDBid, "INSERT INTO Tbl_Client (LastName,FirstName) VALUES ('Smith','John)")
SQLclose($oDBid)

Next time I'll close my mouth for a little longer and do more research! :P

Share this post


Link to post
Share on other sites

just fixed my problem for doing a little more reading!  ;)

followed a link to connectionstrings.com and tried this:

Dim $oDBid,
$oDBid=_SQLOpen("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\database.mdb;Uid=Admin;Pwd=;")
_SQLQuery($oDBid, "INSERT INTO Tbl_Client (LastName,FirstName) VALUES ('Smith','John)")
SQLclose($oDBid)

Next time I'll close my mouth for a little longer and do more research!  :P

<{POST_SNAPBACK}>

Thanks for posting back and letting us know. I find the best way to learn is from mine and other people's mistakes.

Share this post


Link to post
Share on other sites

I tried exactly what's posted above but get this error:

Line 17 (File "C:\Program Files\AutoIt3\Include\sql.au3"):

$adCN.Execute ($query)

$adCN.E^ ERROR

Error: Unable to parse line.

The script I'm using for sql.au3 is shown below. It's lifted directly from this post, so I guess it *should* work, right ? Is it something I've simply not set up properly on my system to use AutoIT3 properly ?

Thanks,

Jamie.

; ------------------------------------------------------------------------------

;

; AutoIt Version: 3.1.1 (beta)

; Language: English

; Description: Functions to handle SQL databases.

;

; ------------------------------------------------------------------------------

Func _SQLConnect($server, $db, $username, $password)

Global $adCN ;&lt;==Declare variable

$adCN = ObjCreate ("ADODB.Connection") ;&lt;==Create SQL connection

$adCN.Open ("DRIVER={SQL Server};SERVER=" &amp; $server &amp; ";DATABASE=" &amp; $db &amp; ";uid=" &amp; $username &amp; ";pwd=" &amp; $password &amp; ";") ;&lt;==Connect with required credentials

EndFunc

Func _SQLClose ()

$adCN.Close ;==&gt;Close the database

EndFunc

Func _SQLExecute( $query )

$adCN.Execute( $query )

EndFunc

Share this post


Link to post
Share on other sites

Ah, thanks Larry. Is it only the Beta version that supports SQL or can I read an Access DB from the release version ? Also, does the beta version currently permit compilation to an executable ?

Thanks,

Jamie.

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  
Followers 0