dbTalk Databases Forums  

validate SQL login before running sqlcmd or osql in WSH

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss validate SQL login before running sqlcmd or osql in WSH in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Hartman_Ralph@Hotmail.com
 
Posts: n/a

Default validate SQL login before running sqlcmd or osql in WSH - 05-10-2009 , 11:29 AM






Hello.

I have a WSH script which reads in a list of servers from my database
(RecordSet("serverName")) and then runs a query against that SQL
Server (DoSomething.sql). Unfortunately in my environment there are
two possible SQL logins that have rights on our server. How could I
check to see if Login1 or Login2 has rights before running the SQLCmd
using Login1 or Login2?


Const SQLCMD = "sqlcmd -i -b DoSomething.sql -t 6015 "
Const SQLLogin1 = "-U Login1 -P MyPassword "
Const SQLLogin2 = "-U Login2 -P MyPassword "

intResult = WshShell.Run(SQLCMD & SQLLogin1 & "-S " & RecordSet
("ServerName"),0,False)

For some reason intResult is not populated after running.
I apologize for putting this in the sql and wsh group, I was not quite
sure where it should be placed (please don't flame me). Any help
would be greatly appreciated.
Hartman_Ralph (AT) hotmail (DOT) com

Reply With Quote
  #2  
Old   
ekkehard.horner
 
Posts: n/a

Default Re: validate SQL login before running sqlcmd or osql in WSH - 05-10-2009 , 12:19 PM






Hartman_Ralph (AT) Hotmail (DOT) com schrieb:
Quote:
Hello.

I have a WSH script which reads in a list of servers from my database
(RecordSet("serverName")) and then runs a query against that SQL
Server (DoSomething.sql). Unfortunately in my environment there are
two possible SQL logins that have rights on our server. How could I
check to see if Login1 or Login2 has rights before running the SQLCmd
using Login1 or Login2?


Const SQLCMD = "sqlcmd -i -b DoSomething.sql -t 6015 "
Const SQLLogin1 = "-U Login1 -P MyPassword "
Const SQLLogin2 = "-U Login2 -P MyPassword "

intResult = WshShell.Run(SQLCMD & SQLLogin1 & "-S " & RecordSet
("ServerName"),0,False)

For some reason intResult is not populated after running.
I apologize for putting this in the sql and wsh group, I was not quite
sure where it should be placed (please don't flame me). Any help
would be greatly appreciated.
Hartman_Ralph (AT) hotmail (DOT) com
Use True as the third parameter (bWaitOnReturn) in the .Run call. *Then*
the shall can return the exit code of the command.


Reply With Quote
  #3  
Old   
Ralph Hartman
 
Posts: n/a

Default Re: validate SQL login before running sqlcmd or osql in WSH - 05-11-2009 , 12:21 PM



Thank you very much, sometimes you get tunnel vision and miss the easy ones.

"ekkehard.horner" wrote:

Quote:
Hartman_Ralph (AT) Hotmail (DOT) com schrieb:
Hello.

I have a WSH script which reads in a list of servers from my database
(RecordSet("serverName")) and then runs a query against that SQL
Server (DoSomething.sql). Unfortunately in my environment there are
two possible SQL logins that have rights on our server. How could I
check to see if Login1 or Login2 has rights before running the SQLCmd
using Login1 or Login2?


Const SQLCMD = "sqlcmd -i -b DoSomething.sql -t 6015 "
Const SQLLogin1 = "-U Login1 -P MyPassword "
Const SQLLogin2 = "-U Login2 -P MyPassword "

intResult = WshShell.Run(SQLCMD & SQLLogin1 & "-S " & RecordSet
("ServerName"),0,False)

For some reason intResult is not populated after running.
I apologize for putting this in the sql and wsh group, I was not quite
sure where it should be placed (please don't flame me). Any help
would be greatly appreciated.
Hartman_Ralph (AT) hotmail (DOT) com

Use True as the third parameter (bWaitOnReturn) in the .Run call. *Then*
the shall can return the exit code of the command.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.