Click here to Skip to main content
11,706,455 members (33,319 online)
Rate this: bad
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).

Posted 29-Dec-12 13:05pm
Richard MacCutchan at 30-Dec-12 3:52am
Don't try to create files in the root of your C: drive.
Rate this: bad
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.
Rate this: bad
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.
Zoltán Zörgő at 31-Dec-12 14:06pm
Not a good one. Read this article:
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 197
1 Sergey Alexandrovich Kryukov 141
2 chainerlt 110
3 Mika Wendelius 80
4 ppolymorphe 71
0 OriginalGriff 9,070
1 Sergey Alexandrovich Kryukov 8,413
2 CPallini 5,189
3 Maciej Los 4,746
4 Mika Wendelius 3,676

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2015
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