Link to home
Start Free TrialLog in
Avatar of Mauro Cazabonnet
Mauro CazabonnetFlag for United States of America

asked on

SQL XPCMDSHELL SQLCMD

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
ASKER CERTIFIED SOLUTION
Avatar of Mauro Cazabonnet
Mauro Cazabonnet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial