Jump to content

Recommended Posts

Posted

Hi,

I'm incredibly new to the AutoIT world but have managed to put together a few simple scripts. Now I have a need to use AutoIT to connect to a Microsoft SQL database and run a query on a table then export the results somewhere.

So far I've read numerous articles about _sql.au3, ADO, COM etc and if I'm honest I don't have much of a clue! Would anyone be able to guide me towards creating a simple script?

Kind regards,

Rob :)

Thanks

Rob

Posted (edited)

Would anyone be able to guide me towards creating a simple script?

Hi Rob,

It's pretty straight forward + a million & one posts out there if you have a look ;)

Trial & error, have a blast & come back if you get stuck!

Basic comms..... then take it from there.....

$sqlcmd="exec stored_proc" ; example, could be just a select statement
$oConn = ObjCreate("ADODB.Connection")
$oConn.ConnectionTimeout = 3 ; default is 15 s
$DSN = "Driver={SQL Server};Server=SERVERNAME\INSTANCE;Database=DBNAME;Uid=U;Pwd=P;" ; Enter the details of your server (ignore the instance if you use default, just add the servername), db, ua to use
$oConn.Open($DSN)
$oConn.Execute($sqlcmd)

Bob

Edited by BobRoss
Posted

Hi Bob,

That seems pretty straight forward, I've amended your script to my settings and my script didn't error, I presume this has made a connection successfully. I have wrote a simple select statement in the $sqlcmd=" section but am unsure as to how I'd get this information it's querying to display. Would you be able to show me that one last thing so I can ensure I am definitely getting connection to the DB then I'll have to take it from there.

Thanks a lot, very much appreciated.

Rob

Thanks

Rob

Posted

Hi Bob,

That seems pretty straight forward, I've amended your script to my settings and my script didn't error, I presume this has made a connection successfully. I have wrote a simple select statement in the $sqlcmd=" section but am unsure as to how I'd get this information it's querying to display. Would you be able to show me that one last thing so I can ensure I am definitely getting connection to the DB then I'll have to take it from there.

Thanks a lot, very much appreciated.

Rob

Hi Rob,

I see.... myself (I'm a DBA for the day job) I tend to call sprocs etc so never actually had the need to actually display the return.

I've just had a quick look & there is quite a bit on the forum which should tie the loose ends & give you something you can custom to your needs;

Cheers

Bob

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
×
×
  • Create New...