Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

xp_cmdshell Expand / Collapse
Author
Message
Posted Monday, July 12, 2010 10:03 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 4:37 AM
Points: 746, Visits: 1,058
Hi,

I execute a command (xp_cmdshell) , but i always receive this error:
Login failed for user 'teste'.


But the user is sysadmin and the password is correct.... and the functionality is already active in the surface area)

Here is the command that i execute:


Declare @osql varchar(8000)
Set @osql='EXEC master.dbo.xp_cmdshell '+''''+'osql -Uteste -Pteste -Q"DBCC Checkdb (''''securdb'''')" -o"C:\teste1.txt"'''''''
EXEC (@osql)



Can someone help?


Thank you
Post #950870
Posted Monday, July 12, 2010 10:31 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 26, 2014 3:36 AM
Points: 1,192, Visits: 698
The xp_cmdshell is calling a command line program called OSQL which is connecting to the default instance on the local computer with the username teste and password teste.

If you are already connected to the default instance on the server you may as well just run DBCC Checkdb ('securdb') in mangagement studio with results to file option selected.
Post #950895
Posted Tuesday, July 13, 2010 6:57 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 26, 2014 6:51 PM
Points: 1,264, Visits: 725
Try to add -S (Servername) option to OSQL command.
Post #951407
Posted Tuesday, July 13, 2010 11:36 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 4:39 PM
Points: 35,262, Visits: 31,748
river1 (7/12/2010)
Hi,

I execute a command (xp_cmdshell) , but i always receive this error:
Login failed for user 'teste'.


But the user is sysadmin and the password is correct.... and the functionality is already active in the surface area)

Here is the command that i execute:


Declare @osql varchar(8000)
Set @osql='EXEC master.dbo.xp_cmdshell '+''''+'osql -Uteste -Pteste -Q"DBCC Checkdb (''''securdb'''')" -o"C:\teste1.txt"'''''''
EXEC (@osql)



Can someone help?


Thank you


Agghh... don't ever hardcode user security information in SQL Server. Use a trusted connection instead of declaring the -U and -P parameters and, as has already been suggested, add the -Sputserverinstancenamehere parameter. I'm not at a machine where I can look up how to declare a trusted connection so you'll need to lookup in Books Online but IIRC, it's -T or -E... can't remember which one.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #952033
Posted Tuesday, July 13, 2010 11:46 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:55 PM
Points: 17,710, Visits: 15,576
Jeff Moden (7/13/2010)
river1 (7/12/2010)
Hi,

I execute a command (xp_cmdshell) , but i always receive this error:
Login failed for user 'teste'.


But the user is sysadmin and the password is correct.... and the functionality is already active in the surface area)

Here is the command that i execute:


Declare @osql varchar(8000)
Set @osql='EXEC master.dbo.xp_cmdshell '+''''+'osql -Uteste -Pteste -Q"DBCC Checkdb (''''securdb'''')" -o"C:\teste1.txt"'''''''
EXEC (@osql)



Can someone help?


Thank you


Agghh... don't ever hardcode user security information in SQL Server. Use a trusted connection instead of declaring the -U and -P parameters and, as has already been suggested, add the -Sputserverinstancenamehere parameter. I'm not at a machine where I can look up how to declare a trusted connection so you'll need to lookup in Books Online but IIRC, it's -T or -E... can't remember which one.


-E is the switch to use.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #952037
Posted Tuesday, July 20, 2010 11:48 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, September 24, 2014 4:50 PM
Points: 358, Visits: 876
It appear you have your string inlcude the EXEC portion already. When you run EXEC (@osql) it seems to come down to
Exec Exec XP_CMDshell .....
ELiminating this may not not fix your issue but may give a slightly different error message.
Or maybe I don't know the workings of the EXEC function well enough.

Best

Mark
Post #956107
Posted Thursday, July 22, 2010 8:53 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, September 26, 2014 1:54 AM
Points: 28, Visits: 449
Try

sp_configure 'xp_cmdshell',1;
reconfigure
Post #957251
Posted Thursday, July 22, 2010 12:53 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 1:50 PM
Points: 1,194, Visits: 2,220
Check whether the SQL Server account has access to C:\teste1.txt.

Thank You,

Best regards,
SQLBuddy
Post #957491
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse