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 ««12

xp_cmdshell works and then doesn't work Expand / Collapse
Author
Message
Posted Thursday, December 6, 2012 1:02 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 2:50 PM
Points: 36,711, Visits: 31,159
mike_macairan (12/6/2012)
It's not that files are being moved. The way this happens is, I open Management Studio, open a query window, type:

exec xp_cmdshell 'Dir C:\'

and execute it.

I get the results (which is a listing of everything in the root of C:\)

I can hit execute a dozen times and, at some point, the result set will change from being the contents of C:\ to NULL, but the files are exactly where they were. I can open a command prompt and do it and get the correct results every time. Once the results become NULL, I can try it a hundred more times and it won't go back to giving me the contents of C:\. If I come back, say, the next day, it may or may not start giving me the contents of C:\ again.

Once it is in that state (returning NULL for everything), the stored procedure will fail, because one of the steps uses xp_cmdshell.

I am thinking that something else is going on within SQL that blocks xp_cmdshell or that hogs it resources or something. And it's not JUST when I do a Dir; it's with anything I try to do using xp_cmdshell.

I know this is a difficult question because I did extensive online searches before posting my question. A lot of people have had this problem, most of the answers are off-track because it's kind of hard to explain the symptoms--and the only one of those posts where the solution was found was one where the Antivirus program was preventing xp_cmdshell. I don't have an antivirus program on here (I took it off for troubleshooting) and the firewall is turned off.


Thanks for the feedback on this. I'm not sure what the problem is because I've just tried what you did on two of my servers and my local box. I even tried the following...

exec xp_cmdshell 'Dir C:\' 
GO 99


No sign of the NULL problem you're reporting. This is also the first time I've ever heard of someone having such a problem but, of course, I've never searched for it before, either.


--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 #1393718
Posted Monday, May 12, 2014 2:04 PM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 2, 2014 1:18 PM
Points: 21, Visits: 88
Did you ever find out why xp_cmdshell only worked intermittently? I have a similar problem, but mine is running BCP and it just hangs. I have to restart the SQL Server to get BCP to stop.

The BCP code used to work, but then it just stopped working a few days ago and hasn't worked since. It is not BCP, because I can run that manually from the Cmd prompt with no problem. I cannot manually run xp_cmdshell with the BCP command from SSMS and I get a syntax error.

Any insights would be appreciated. Thanks!
Post #1570048
Posted Monday, May 12, 2014 3:13 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 2:50 PM
Points: 36,711, Visits: 31,159
Sorry... responded to an older post on this thread that had already been answered so removed my duplication.

--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 #1570061
Posted Monday, May 12, 2014 3:16 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 2:50 PM
Points: 36,711, Visits: 31,159
JustOffal (5/12/2014)
Did you ever find out why xp_cmdshell only worked intermittently? I have a similar problem, but mine is running BCP and it just hangs. I have to restart the SQL Server to get BCP to stop.

The BCP code used to work, but then it just stopped working a few days ago and hasn't worked since. It is not BCP, because I can run that manually from the Cmd prompt with no problem. I cannot manually run xp_cmdshell with the BCP command from SSMS and I get a syntax error.

Any insights would be appreciated. Thanks!


Please post the command that's giving the error and the actual error captured from the screen. Thanks.


--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 #1570065
Posted Tuesday, May 13, 2014 12:07 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, July 18, 2014 2:05 PM
Points: 3,943, Visits: 2,957
JustOffal - I'm incredibly curious about this one, too. Please post the command and the output.

Jeff - You know I'm thinking of your presentation that isn't ready yet.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1570496
Posted Tuesday, May 13, 2014 5:03 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 2:50 PM
Points: 36,711, Visits: 31,159
Ed Wagner (5/13/2014)
JustOffal - I'm incredibly curious about this one, too. Please post the command and the output.

Jeff - You know I'm thinking of your presentation that isn't ready yet.


That's what I'm thinking, as well.


--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 #1570583
Posted Wednesday, May 14, 2014 11:13 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 2, 2014 1:18 PM
Points: 21, Visits: 88
Hi, I'm sorry but I cannot reproduce the error anymore. I removed a few comments from the sp that calls bcp, and it started working again. The issue no longer exists and I don't want it to come back.

Thanks for your responses!
Post #1570955
Posted Wednesday, May 14, 2014 12:37 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, July 18, 2014 2:05 PM
Points: 3,943, Visits: 2,957
Glad to hear it worked out for you in the end.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1570976
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse