AutoIT – Connecting to SQL Server.
Playing around with AutoIt take me to next level of coding.
This time I need to automate a process where in a normal situation it will involve a few people to make the whole process completed.
One of the process need a connection to MS-SQL ,execute query and and get the results. As sharing is caring, here I share how to connect to SQL-Server using AutoIt.
$conn = ObjCreate( "ADODB.Connection" )
$DSN = "DRIVER={SQL Server};SERVER=MySvr;DATABASE=MyDB;UID=MyUser;PWD=MyPwd;"
$conn.Open($DSN)
$rs = ObjCreate( "ADODB.RecordSet" )
$rs.Open( "SELECT @@VERSION AS myVersion", $conn )
MsgBox(0, "AutoIT-SQL Result", "Value = " & $rs.Fields( "myVersion" ).Value )
$conn.close
The code will produce a msg box like below.

Here you go…it’s only the basic code. You can do a lot more than this.
Have a nice weekend.
p/s: I have a job to do this weekend…..so..not a very nice weeked for me.adoii….

9 Responses to “AutoIT – Connecting to SQL Server.”
By Halim-Belajar SEO on Jul 21, 2008 | Reply
I once used autoit for making a bot for angels online but its quite so I stop. Autoit is quite good if you know programming and definitely not for me douh..
Halim-Belajar SEO’s last blog post..Using GoDaddy for domain registration.
By arejae on Jul 22, 2008 | Reply
yeah…need to know at least a little bit programming.
spammer also like this kind of automate tools.
By Sarfraz Shah on Oct 17, 2008 | Reply
Thanks
By admin on Apr 5, 2010 | Reply
Hi Scary, read my post here.
http://www.arejae.com/blogv2/error-handling-in-autoit.html
By DBA on Jul 29, 2010 | Reply
I’ve Found a SQL scanner that can locate any SQL server at your network (multi-subnet) it can also try to brute force the SA user account (or any other account) to make sure the password is not easy.
you can get it here: http://www.softpedia.com/get/Internet/Servers/Database-Utils/SQL-Locator.shtml
By Shreeks on May 3, 2011 | Reply
$conn = ObjCreate( “ADODB.Connection” )
$DSN = “{SQL Server (jTDS)};SERVER=Ctsintcosead;DATABASE=ESAReports_DevArea;UID=wfd_read;PWD=wfd_read;”
$conn.Open($DSN)
$rs = ObjCreate( “ADODB.RecordSet” )
$rs.Open( “SELECT @@VERSION AS myVersion”, $conn )
MsgBox(0, “AutoIT-SQL Result”, “Value = ” & $rs.Fields( “myVersion” ).Value )
$conn.close
I tried with the above code but there is an error popping up :
C:\Users\171067\Desktop\DB_Connect\DB_Connect_try2.au3 (3) : ==> The requested action with this object has failed.:
$conn.Open($DSN)
$conn.Open($DSN)^ ERROR
Could anyone help us with this issue? Thanks.
By dabu_tvd on Feb 3, 2012 | Reply
@Shreeks try codes below:
$conn = ObjCreate( “ADODB.Connection” )
$DSN = “DRIVER={SQL Server};SERVER=Ctsintcosead;DATABASE=ESAReports_DevArea;UID=wfd_read;PWD=wfd_read;”
$conn.Open($DSN)
$rs = ObjCreate( “ADODB.RecordSet” )
$rs.Open( “SELECT @@VERSION AS myVersion”, $conn )
MsgBox(0, “AutoIT-SQL Result”, “Value = ” & $rs.Fields( “myVersion” ).Value )
$conn.close