We help IT Professionals succeed at work.

SQL XPCMDSHELL SQLCMD

137 Views
Last Modified: 2017-05-05
Hi,
I'm trying to run a sqlcmd from sql server1 on remote sql server2

I setup the proxy account
XEC MASTER.dbo.sp_xp_cmdshell_proxy_account 'domain\user', 'password'

SET @dbname = 'Vantage'
	SET @ReplicaServer = 'Server2'
	SET @SQLCMD = 'SQLCMD -S' + @ReplicaServer + ' -Q ' 
	SET @command = 'SELECT CURRENT_USER'

	SET @CommandText = @SQLCMD + '"' + @command + '"' 
	PRINT @CommandText 
	EXEC MASTER.dbo.Xp_cmdshell @CommandText --Drop database on secondary server

Open in new window


I'm getting the following output

output
                                                                                                                               
--------------------------------------------------------------------------------------------------------------------------------
guest                                                                                                                          
NULL
(1 rows affected)
NULL

I need it to be dbo
Since I would like to drop a database and whatever else on server2

What am I missing here?

Thanks in advance
Comment
Watch Question

Senior Windows Automation Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.