Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
/* example from help .. "Access is denied" along with a pesky "NULL" on another line */
 
DECLARE @cmd sysname, @var sysname
SET @var = 'Hello world'
SET @cmd = 'echo ' + @var + ' > C:\var_out.txt'
EXEC master..xp_cmdshell @cmd
Experimenting with the form:
EXEC xp_cmdshell '@echo SELECT [blahblah] FROM [dbo].[masterblah] WHERE [blahIdx] = 1 >> J:\blahOutput.txt'
Alternatives would be great. But ... this should work (been there, done it before).
 
Thanks
Posted 29-Dec-12 14:05pm
RedDk10K
Comments
Richard MacCutchan at 30-Dec-12 3:52am
   
Don't try to create files in the root of your C: drive.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The chances are that the problem is just the destination of your file: Vista and above require full admin rights to write or modify any file in the root directory of your boot drive. The user under which SQL server is executing will not have that permission. Change the folder: either to a created folder which as "open" access for all users, or an existing data directory which does.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Found solution.
 
And I had done this before. Simple change of the service type. From "NETWORK SERVICES" to "LOCAL SYSTEM".
 
This can be done in Computer Managment console; "Log on As" tab of the Properties.
  Permalink  
Comments
Zoltán Zörgő at 31-Dec-12 14:06pm
   
Not a good one. Read this article: http://thinkingeek.com/2008/11/13/controlling-the-commands-executed-with-xp_cmdshell-on-sql-server-2005/
RedDK at 31-Dec-12 14:18pm
   
... of note, also, is that ssmse execution requires dir /x path notation to be of any use here in this scenario. Aggrevating, yes?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 255
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100