473,466 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using BCP/xp_cmdshell as NON serveradmin

I have created a view named viewOutput that shows one column in a
table.
I insert a row into the table and then I'm using this code to create a
file with the text in the single row.

This code works fine when I'm signed on with an account that has
server admin rights, however it fails when I signin with an account
that does not have server admin rights.

I'm hoping someone can help me with this.
Alter PROCEDURE OutputOrders
@FileName nvarchar(50)

AS
set nocount on

DECLARE @ReturnCode int
DECLARE @ExportCommand varchar(255)

SET @ExportCommand =
'BCP myServerName.dbo.viewOutput out "c:\output\order files\' +
@TemplateFileName +
'" -T -c -S ' + @@SERVERNAME
EXEC @ReturnCode = master.dbo.xp_cmdshell @ExportCommand
I have granted execute permission to xp_cmdshell for both users.
Jul 20 '05 #1
2 2506
la*************@hotmail.com (Lauren Quantrell) wrote in message news:<47**************************@posting.google. com>...
I have created a view named viewOutput that shows one column in a
table.
I insert a row into the table and then I'm using this code to create a
file with the text in the single row.

This code works fine when I'm signed on with an account that has
server admin rights, however it fails when I signin with an account
that does not have server admin rights.

I'm hoping someone can help me with this.
Alter PROCEDURE OutputOrders
@FileName nvarchar(50)

AS
set nocount on

DECLARE @ReturnCode int
DECLARE @ExportCommand varchar(255)

SET @ExportCommand =
'BCP myServerName.dbo.viewOutput out "c:\output\order files\' +
@TemplateFileName +
'" -T -c -S ' + @@SERVERNAME
EXEC @ReturnCode = master.dbo.xp_cmdshell @ExportCommand
I have granted execute permission to xp_cmdshell for both users.


Unfortunately, you didn't explain what "fails" means - what is the
error? But I guess that probably you haven't enabled the SQL Agent
proxy account. When a sysadmin runs xp_cmdshell, the commands executes
in the security context of the MSSQL service account, however for
non-sysadmins you need to specify an account to use. See the Remarks
section for xp_cmdshell in Books Online.

Simon
Jul 20 '05 #2
Simon,
After posting I found an excellent article by Dan Guzman on this
subject at: http://www.winnetmag.com/Articles/Index.cfm (search for
article #25145)
Thanks
sq*@hayes.ch (Simon Hayes) wrote in message news:<60**************************@posting.google. com>...
la*************@hotmail.com (Lauren Quantrell) wrote in message news:<47**************************@posting.google. com>...
I have created a view named viewOutput that shows one column in a
table.
I insert a row into the table and then I'm using this code to create a
file with the text in the single row.

This code works fine when I'm signed on with an account that has
server admin rights, however it fails when I signin with an account
that does not have server admin rights.

I'm hoping someone can help me with this.
Alter PROCEDURE OutputOrders
@FileName nvarchar(50)

AS
set nocount on

DECLARE @ReturnCode int
DECLARE @ExportCommand varchar(255)

SET @ExportCommand =
'BCP myServerName.dbo.viewOutput out "c:\output\order files\' +
@TemplateFileName +
'" -T -c -S ' + @@SERVERNAME
EXEC @ReturnCode = master.dbo.xp_cmdshell @ExportCommand
I have granted execute permission to xp_cmdshell for both users.


Unfortunately, you didn't explain what "fails" means - what is the
error? But I guess that probably you haven't enabled the SQL Agent
proxy account. When a sysadmin runs xp_cmdshell, the commands executes
in the security context of the MSSQL service account, however for
non-sysadmins you need to specify an account to use. See the Remarks
section for xp_cmdshell in Books Online.

Simon

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Yvonne | last post by:
Would like to implement Blat on SQL Server 2000. I'm looking for example syntax for setting up BLAT with xp_cmdshell. TIA
3
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare...
4
by: Joel Thornton | last post by:
Whenever something is inserted to a given table, I want to run some shell commands using xp_cmdshell. Would it be a bad idea to put this xp_cmdshell in the INSERT trigger of this table? I...
2
by: Eirik Oppen | last post by:
Hi, I'm having some trouble finding any information on this topic - can MS SQL server 2000 copy/delete files on the host computers disk. Any info on this would be great. Thanks, Eirik
9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
1
by: Micah Gentry | last post by:
Is there any way to allow a user to use the xp_cmdshell extended stored procedure without giving that user execute permissions to xp_cmdshell in SQL server 6.5? Let me clarify. Lets say I (as the...
4
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell...
2
by: Maddman | last post by:
Newbie here. In my database I'm needing to automate some data imports. I have the import set up as a DTS package and it works wonderfully. But I'm having trouble kicking it off as a stored...
6
by: mcolson | last post by:
Is it possible to use sql to execute a batch file? I would like to execute the following "C:\BTW\bartend.exe /f=C:\BTW\Toolbox\Formats \carnum.btw /p", 6 Thanks, Matt
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.