Example for connection to MS SQL Server / MacroScheduler 10

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

Example for connection to MS SQL Server / MacroScheduler 10

Post by matthiasR » Mon Apr 14, 2008 8:45 pm

Hi,

could someone give me an example, how to connect to an MS SQL Server and doing a "select" using the new db feature in MacroScheduler10.

Regards,

Matthias

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Apr 14, 2008 9:06 pm

You just need the appropriate connection string for your MS SQL Server in the DBConnect line. Otherwise everything else is the same. Read your SQL Server manual to see what the connection string is.

Or use Google:

http://www.google.com/search?q=MS+SQL+S ... ion+String
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

Post by matthiasR » Tue Apr 15, 2008 10:40 am

Thanks for the hint.

The following script works

Code: Select all

DBConnect>Driver={SQL Server};Server=192.168.168.33;Database=sale;Uid=sa;Pwd=12345;,dbH
DBQuery>dbH,select * from AEL where aranummer =10,rset,NumRecs,NumFields
dbclose>dbH
While the following script does not return any result

Code: Select all

DBConnect>Driver={SQL Server};Server=192.168.168.33;Database=sale;Uid=sa;Pwd=12345;,dbH
DBQuery>dbH,select aranummer, artyp from AEL where aranummer =10,rset,NumRecs,NumFields
dbclose>dbH
It works also with one fieldname after select

Code: Select all

DBQuery>dbH,select aranummer from AEL where aranummer =10,rset,NumRecs,NumFields

The failing select expression works in SQL ServerManagementStudio.

Am i doing something wrong?

Regards,

Matthias

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Apr 15, 2008 10:46 am

Your SQL has commas in it. So do this:

Code: Select all

DBConnect>Driver={SQL Server};Server=192.168.168.33;Database=sale;Uid=sa;Pwd=12345;,dbH

Let>SQL=select aranummer, artyp from AEL where aranummer =10

DBQuery>dbH,SQL,rset,NumRecs,NumFields

DBClose>dbH
I think it's more readable to put the SQL in a variable anyway.

I have just written a blog post about the new DB commands here:
http://www.mjtnet.com/blog/2008/04/15/u ... functions/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

matthiasR
Pro Scripter
Posts: 52
Joined: Tue Jan 20, 2004 3:45 pm
Location: Lübbecke, Germany

Post by matthiasR » Thu Apr 17, 2008 10:04 am

I missed the commas in the sql expression. You are absolutely right: Its better to put the sql statement in a variable.

Thanks,

Matthias

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts