473,654 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xp_cmdshell from within a trigger on SQL 2000 SP4

I have a trigger that should be execute on each row insert and only if
appcode = 'I' and datasent = 0. It should execute a DTS package. The
DTS package by itself runs about 6 seconds. Trigger was created
successfuly. When I try to insert a row my db hangs. I can see that
SPID on my db is hang by SPID from master db. It doesn't complete
until I kill that SPID. Why is that?
This is the trigger that I am trying to execute:
CREATE TRIGGER myExport
ON ruExport

FOR INSERT
AS
declare @appcode varchar (10)
select @appcode = appcode from ruexport where appcode = 'I' and
datesent = 0

if @appcode = 'I'
exec master..xp_cmds hell 'DTSRun /S "KOCL384017 SQL" /N "Sys_Export " /G
"{17D112A8-413E-420F-A624-3790BDFBED9F}" /W "0" /E'

go

Any suggestions?

Jan 19 '07 #1
2 4259
tolcis,

There are a couple of considerations you might want to think about here.

1. Triggers should be designed as set operations. A trigger only fires once
for each batch that is being updated. If the batch updates multiple rows,
then your trigger should account for it. As it is written, your trigger
assumes only one row is getting updated.

2. You are already selecting a set where the appcode = 'I', why the if
@appcode = 'I' comparison later in the trigger?

3. Personal architectural philosophy: I would not execute a DTS package
directly from a trigger. There are many external kinds of issues that can
cause a DTS package to fail. I would make the interaction with the DTS
package more loosely coupled with the application. An alternative would be
to have the DTS package set up a job to run once a minute ( or hour, etc.).
First job step could check to see if any rows have to be processed ( appcode
= 'I' and datesent = 0). If none need to be processed then exit the job
with success, otherwise execute the DTS package.

-- Bill

"tolcis" <ny********@gma il.comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.com...
>I have a trigger that should be execute on each row insert and only if
appcode = 'I' and datasent = 0. It should execute a DTS package. The
DTS package by itself runs about 6 seconds. Trigger was created
successfuly. When I try to insert a row my db hangs. I can see that
SPID on my db is hang by SPID from master db. It doesn't complete
until I kill that SPID. Why is that?
This is the trigger that I am trying to execute:
CREATE TRIGGER myExport
ON ruExport

FOR INSERT
AS
declare @appcode varchar (10)
select @appcode = appcode from ruexport where appcode = 'I' and
datesent = 0

if @appcode = 'I'
exec master..xp_cmds hell 'DTSRun /S "KOCL384017 SQL" /N "Sys_Export " /G
"{17D112A8-413E-420F-A624-3790BDFBED9F}" /W "0" /E'

go

Any suggestions?

Jan 19 '07 #2
To add to AlterEgo's response, note that the DTS package is an external
process and not running in the trigger transaction context. If the DTS
package accesses uncommitted data from the INSERT statement, it will be
blocked until the INSERT completes. However, the INSERT can't complete
until the DTS package executed from the trigger completes. This is a
deadlock that requires you to KILL the spid.

A better application design is to have the trigger insert into a queue table
like AlterEgo suggested and have a separate perform the process
asynchronously.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"tolcis" <ny********@gma il.comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.com...
>I have a trigger that should be execute on each row insert and only if
appcode = 'I' and datasent = 0. It should execute a DTS package. The
DTS package by itself runs about 6 seconds. Trigger was created
successfuly. When I try to insert a row my db hangs. I can see that
SPID on my db is hang by SPID from master db. It doesn't complete
until I kill that SPID. Why is that?
This is the trigger that I am trying to execute:
CREATE TRIGGER myExport
ON ruExport

FOR INSERT
AS
declare @appcode varchar (10)
select @appcode = appcode from ruexport where appcode = 'I' and
datesent = 0

if @appcode = 'I'
exec master..xp_cmds hell 'DTSRun /S "KOCL384017 SQL" /N "Sys_Export " /G
"{17D112A8-413E-420F-A624-3790BDFBED9F}" /W "0" /E'

go

Any suggestions?
Jan 20 '07 #3

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

Similar topics

5
2133
by: dananrg | last post by:
I've created a small company database where the tables reside in a SQL Server database. I'm using Access 2000 forms for a front end. I've got a System DSN set-up to SQL Server and am using links within Access 2000 to get to the SQL Server tables. My forms worked fine until I made a few minor changes to the database schema on SQL Server (e.g. added a foreign key, or added a column). After that, all the links break - I click on a table...
3
2662
by: Gustavo Randich | last post by:
The following seems to be a bug. The execution returns rows 1,2. It should return 1,1. In fact, if I run the code within a stored procedure alone (not in a trigger), the loop doesn't overwrite the value of y (works well). create table test (a integer) @ create table debug1 (a integer) @ create trigger test_1 after insert on test referencing new as ins for
1
1074
by: ligi168 | last post by:
Hi,can anybody help me? One question has confused me for a long time.That is we can use api within excel 2000 by delare syntax,but some dll file cannot be referred and an error appeared like "no entrance in the dll file". Why? Thanks. Agan
0
1769
by: Freddy | last post by:
In my Access db (which I have created to help me learn Greek) I am using text box controls on a form. Some of these controls require English input and some require Greek input. Currently I have to keep toggling the keyboard input language bar settings manually from the keyboard whenever I wish to switch languages - this is a real pain. What I would like is for the keyboard language to be changed automatically to the appropriate...
0
1316
by: ismailc | last post by:
hi, i need help please! i have a macro within an excel file(c:\test.xls) called macro1, how do i get it to execute? xl_app.run macro1 (the area of concern, this does not work) (full code in example below) how to call & execute the macro within an excel file? anyone help please ********* code ****************
1
1705
by: akshaysk | last post by:
HI, I am new to Visual Basic. For my Assignment i am supposed to write a visual basic program using excel. I have tried many scripts, but receive errors. Can anyone tell me of any website that explain using visual basic in excel? The Assignment is due very soon,so is there anyone who can create a code a problem. thank for your help. akshay
1
8306
by: shark | last post by:
hi, does anybody know how to enable/disable xp_cmdshell in sql server 2000. i our server this sp has been disbaled for security puropse.but i need to use it in a job.so please can any body guide me? thanks for the help.
0
1367
by: fpwilliams71 | last post by:
I have tried to write functions within SQL 2000 that would mimic the DSum funcion found in MS Access without any luck. This I could achieve withing Vb 6.0. I would rather have it done within MS SQL for better system through-put
1
1471
by: AngieMP | last post by:
Hi Guys I have inherited an Access DB in a very poorly state! I have offered to make some changes to it for a local charity but have got stuck on this error it seems to be creating for all new records. I am working within a Form which is calling another Form matched on the ID, this is within Access 2000. Clicking the cmdLinkExistingCaredFor_Click produces an Error 6: Overflow error. Can anyone help me as to what maybe making the code...
4
1486
by: Wrighttrak | last post by:
In VBA behind a Command Button I want to copy a directory to a new directory. Ive tried FileCopy but I dont know how to use *.* in that command
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
7304
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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 we have to send another system
2
1592
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.