Click here to Skip to main content
13,597,963 members
Rate this:
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 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ő 31-Dec-12 14:06pm
Not a good one. Read this article:
RedDk 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03-2016 | 2.8.180621.3 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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