The_Lorax Posted September 14, 2005 Posted September 14, 2005 (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=_SqlopenDim $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 connectionI 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 September 14, 2005 by The_Lorax
The_Lorax Posted September 14, 2005 Author Posted September 14, 2005 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!
SumTingWong Posted September 14, 2005 Posted September 14, 2005 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! <{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.
Jamie Posted November 7, 2005 Posted November 7, 2005 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 ;<==Declare variable $adCN = ObjCreate ("ADODB.Connection") ;<==Create SQL connection $adCN.Open ("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";") ;<==Connect with required credentials EndFunc Func _SQLClose () $adCN.Close ;==>Close the database EndFunc Func _SQLExecute( $query ) $adCN.Execute( $query ) EndFunc
Jamie Posted November 7, 2005 Posted November 7, 2005 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now