Solved

BCP Command Freeze inside a SQL Trigger , SQL Server 2008 R2

Posted on 2010-08-27
5
1,078 Views
Last Modified: 2012-05-10
Hi,

I create a trigger, to insert data into a temp table and after extract those data with a bcp command, and cleanup the table after.

Everything work fine in part, but in the trigger itself. Everything freeze when I insert data and this seems to be causes by the BCP command, because the file is created, but nothing is inside. I need to restart SQL server.

Any idea ?

This is a simplify version of the trigger :

insert into Triggers.dbo.TEMP (ITEM,[DESC],SHIUNIT,QTYSHIPPED, UNITCONV, LOCATION,transactiondatetime) Select ITEM,[DESC],SHIUNIT,QTYSHIPPED, UNITCONV, LOCATION, @transactiondatetime from inserted

set @Query = 'bcp "SELECT  ITEM,[DESC],SHIUNIT,QTYSHIPPED, UNITCONV, LOCATION,transactiondatetime FROM Triggers.dbo.temp" queryout'
set @Query = @Query + ' "e:\temp.log" ' + '-U sa -P xxx -c -S' + ' localhost'

delete from Triggers.dbo. temp where transactiondatetime = @transactiondatetime

exec master..xp_cmdshell @Query
 
thanks
0
Comment
Question by:bmdgi
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
carsRST earned 500 total points
Comment Utility
try using a NOLOCK in your BCP query.
0
 
LVL 16

Expert Comment

by:carsRST
Comment Utility
0
 
LVL 1

Author Comment

by:bmdgi
Comment Utility
I Try, but now the file doesn't create...

Really strange....

Any other idea?
0
 
LVL 1

Author Comment

by:bmdgi
Comment Utility
I the issue with the NOLOCK and I needed to add the -o for the Output Files.

Both Fix my issue.

0
 
LVL 1

Author Closing Comment

by:bmdgi
Comment Utility
Need to add the -o and an output file with the NOLOCK

Thanks!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now