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

Home Posts Topics Members FAQ

XP_cmdshell not working

gauravgmbhr
107 New Member
Hi,

I require a trigger that dumps the updated row into a txt file.
I am trying to achieve this using XP_CMDSHELL and bcp

Expand|Select|Wrap|Line Numbers
  1. ALTER TRIGGER Dump_text
  2.    ON  dbo.XXXX
  3.    AFTER INSERT,UPDATE
  4. AS 
  5. declare @bcp_command varchar(300)
  6. BEGIN
  7.     -- SET NOCOUNT ON added to prevent extra result sets from
  8.     SET NOCOUNT ON;
  9.        SELECT @bcp_command = 'bcp "SELECT * FROM DSeries..ESP_XXXX WHERE identifier='''+identifier+'''" queryout c:\gaurav.txt -c -t -UAAA -P BBBB"' FROM inserted
  10.     --SELECT @bcp_command = 'MD TEST'
  11.     EXEC master..xp_cmdshell @bcp_command
  12.  
  13. END
  14. GO
  15.  
The @bcp_command works fine if i run it thru DOS. But whenever triggers submits the BCP operation time outs. Also i have tried submitting different command , they all work fine accept the one i need.

Can some one please tell me why its timing out.
Mar 21 '08 #1
2 3445
ck9663
2,878 Recognized Expert Specialist
Hi,

I require a trigger that dumps the updated row into a txt file.
I am trying to achieve this using XP_CMDSHELL and bcp

Expand|Select|Wrap|Line Numbers
  1. ALTER TRIGGER Dump_text
  2.    ON  dbo.XXXX
  3.    AFTER INSERT,UPDATE
  4. AS 
  5. declare @bcp_command varchar(300)
  6. BEGIN
  7.     -- SET NOCOUNT ON added to prevent extra result sets from
  8.     SET NOCOUNT ON;
  9.        SELECT @bcp_command = 'bcp "SELECT * FROM DSeries..ESP_XXXX WHERE identifier='''+identifier+'''" queryout c:\gaurav.txt -c -t -UAAA -P BBBB"' FROM inserted
  10.     --SELECT @bcp_command = 'MD TEST'
  11.     EXEC master..xp_cmdshell @bcp_command
  12.  
  13. END
  14. GO
  15.  
The @bcp_command works fine if i run it thru DOS. But whenever triggers submits the BCP operation time outs. Also i have tried submitting different command , they all work fine accept the one i need.

Can some one please tell me why its timing out.
Is time out your only problem? I mean if you do an xp_cmdshell in query analyzer, is it working? The reason am asking is because this system stored proc is not enable by default.

Assuming you have xp_cmdshell configured properly and it's working on other part of your SP.

I would assume (read: not sure) you're putting too much stress on your server if you put the xp_cmdshell - bcp inside a trigger. This would mean every time there's an INSERT or UPDATE on your table, this will fire and we're talking per row. That could be the reason for the time out. I would recommend you dump all inserted rows into a table and after the INSERT or UPDATE command, do the bcp.

-- CK

-- CK
Mar 21 '08 #2
gauravgmbhr
107 New Member
Is time out your only problem? I mean if you do an xp_cmdshell in query analyzer, is it working? The reason am asking is because this system stored proc is not enable by default.

Assuming you have xp_cmdshell configured properly and it's working on other part of your SP.

I would assume (read: not sure) you're putting too much stress on your server if you put the xp_cmdshell - bcp inside a trigger. This would mean every time there's an INSERT or UPDATE on your table, this will fire and we're talking per row. That could be the reason for the time out. I would recommend you dump all inserted rows into a table and after the INSERT or UPDATE command, do the bcp.

-- CK

-- CK
Well XP_cmdshell is working with other commands, like CD MD ,RD, DIR, but not with BCP, the row inserts or UPDATES are very few, hardly 2 or 3 a day.
Mar 24 '08 #3

Sign in to post your reply or Sign up for a free account.

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...
5
by: Narine | last post by:
Hi Folks, I am using an xp_cmdshell sp to start a C# app. This app downloads data files and imports them into DB. It has a logging functionality built-in and when executed from the command line...
2
by: Lauren Quantrell | last post by:
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...
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...
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...
4
by: Chris Allison | last post by:
I am getting the following error when running a command in Query Analyzer. Msg 50001, Level 1, State 50001 xpsql.cpp: Error 5 from CreateProcess on line 675 Here is the command that I am...
2
by: m3ckon | last post by:
Please help me? I am writting an upload page in asp.net (using vb.net) for my intranet. I have got the upload working ok, and I then want to run a stored proc which will run a dts command using...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.