Solved

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

Posted on 2010-08-27
5
1,137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

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

Expert Comment

by:carsRST
ID: 33546575
0
 
LVL 1

Author Comment

by:bmdgi
ID: 33547964
I Try, but now the file doesn't create...

Really strange....

Any other idea?
0
 
LVL 1

Author Comment

by:bmdgi
ID: 33592321
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
ID: 33592332
Need to add the -o and an output file with the NOLOCK

Thanks!
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL to JSON 14 59
calculate days away 11 59
grouping by date only 6 21
T-SQL: How to append a column for serialized JSON data? 2 45
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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