SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


xp_cmdshell


xp_cmdshell

Author
Message
river1
river1
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4412 Visits: 1366
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
James_B
James_B
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1351 Visits: 738
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.
magasvs
magasvs
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2373 Visits: 756
Try to add -S (Servername) option to OSQL command.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (214K reputation)SSC Guru (214K reputation)SSC Guru (214K reputation)SSC Guru (214K reputation)SSC Guru (214K reputation)SSC Guru (214K reputation)SSC Guru (214K reputation)SSC Guru (214K reputation)

Group: General Forum Members
Points: 214024 Visits: 41979
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)SSC Guru (66K reputation)

Group: General Forum Members
Points: 66341 Visits: 18570
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, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

MMartin1
MMartin1
SSCertifiable
SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)

Group: General Forum Members
Points: 7201 Visits: 2033
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

----------------------------------------------------
How to post forum questions to get the best help
nekonecny
nekonecny
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 493
Try

sp_configure 'xp_cmdshell',1;
reconfigure
sqlbuddy123
sqlbuddy123
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6102 Visits: 2243
Check whether the SQL Server account has access to C:\teste1.txt.

Thank You,

Best regards,
SQLBuddy
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search