Using SQLCMD from MS SQL-Server 2005 under MS Vista

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
migro
Macro Veteran
Posts: 152
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Using SQLCMD from MS SQL-Server 2005 under MS Vista

Post by migro » Mon Feb 18, 2008 5:00 pm

Hi,

I like to run sqlcmd directly passing some variables from Macro scheduler as commandline parameters. I think that I got here a Problem with the quotations. Other problem seems to be the VISTA UAC as described in the next step.

Next Problem is to restart the server. Under Win XP no Poblem but under Vista it won't work. Is there a possibility to run command with admin rights?

Codesample:

Code: Select all

Let>OldSQLServer=OldHostname
Let>Aktion=Instancename
Let>NewSQLServer=NewHostname
Let>TempPath=C:\macro.log


Label>DropSrv1
   Run Program>sqlcmd.exe -S .\%Aktion% -E -Q "EXECUTE sp_dropserver '%OldSQLServer%'" -o %TempPath%%CRLF%

Label>AddSrv1
   Run Program>sqlcmd.exe -S .\%Aktion% -E -Q "EXECUTE sp_addserver '%NewSQLServer%\%Aktion%', local" -o %TempPath%%CRLF%


Label>RestartSrv1
   Let>RP_WINDOWMODE=0
   Run Program>cmd /c Net stop "SQL Server (%Aktion%)"
   Wait>%WParam%
   Run Program>cmd /c Net start "SQL Server (%Aktion%)"
Thanks for any ideas
regards
migro

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

Post by Marcus Tettmar » Mon Feb 18, 2008 10:14 pm

To run with admin rights issue:

Let>RP_ADMIN=1

Not sure why you have appended CRLF to the end of the command strings.

Quotes should be used just as they would be used if you were issuing the commands from a DOS prompt. Usually they are only required where there are spaces within the command/parameters. But it can depend on the program/command you are calling, so you should check the docs for that app in question.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
migro
Macro Veteran
Posts: 152
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Post by migro » Mon Feb 18, 2008 11:29 pm

Hi,

thanks for the help.

> Not sure why you have appended CRLF to the end of the command strings.
Intention was to get CRLF between the logentries. But when I'm now thinking about it ... SQLcmd won't understand this ;-)
regards
migro

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