Click here to Skip to main content
15,887,364 members
Home / Discussions / Database
   

Database

 
AnswerRe: Optimization - newbie problem Pin
Edbert P31-Oct-05 12:28
Edbert P31-Oct-05 12:28 
GeneralRe: Optimization - newbie problem Pin
gbaii1-Nov-05 7:31
gbaii1-Nov-05 7:31 
QuestionMessage for Vijay Mathew Pandyalakal re Easy_odbc Pin
mville28-Oct-05 21:02
mville28-Oct-05 21:02 
Questionconnect to remote oracle Database Pin
odukuye28-Oct-05 10:40
odukuye28-Oct-05 10:40 
QuestionADV ICE WANTED!! Pin
jaygreen928-Oct-05 8:59
jaygreen928-Oct-05 8:59 
AnswerRe: ADV ICE WANTED!! Pin
Colin Angus Mackay28-Oct-05 13:19
Colin Angus Mackay28-Oct-05 13:19 
QuestionProblem with working SQL Server SAVE POINTS in Transactions. Pin
farhan197627-Oct-05 20:11
farhan197627-Oct-05 20:11 
QuestionTriggers and transaction context. Pin
devvvy27-Oct-05 6:15
devvvy27-Oct-05 6:15 
Hi, I'm running into a situation:

<br />
trx = conn.BeginTransaction();<br />
acc = AccBean.Load(acc_id, conn);<br />
request = RequestBean.Load(request_id, conn);<br />
<br />
//STEP 1: check and validate acc has sufficient funds<br />
if (acc.Balance >= request.Amount) {<br />
  <br />
   //STEP 2: update request status<br />
   request.Status = Status.APPROVED;<br />
<br />
   //STEP 3: approve request - update acc balance<br />
   acc.Balance = acc.Balance - request.Amount;<br />
}<br />
trx.Commit();<br />


This works fine. But one of our DBA insisted on STEP 3 being done by UPDATE trigger - and the code became:

<br />
trx = conn.BeginTransaction();<br />
acc = AccBean.Load(acc_id, conn);<br />
request = RequestBean.Load(request_id, conn);<br />
<br />
//STEP 1: check and validate acc has sufficient funds<br />
if (acc.Balance >= request.Amount) {<br />
  <br />
   //STEP 2: update request status - Now we have an UPDATE trigger on "request" table - to update acc Balance.<br />
   request.Status = Status.APPROVED;<br />
<br />
}<br />
trx.Commit();<br />


The problem is, the trigger is trying to update "acc", which is locked during the duration of the transaction. Is there anyway to get around this? Or is UPDATE TRIGGER a bad idea (TRIGGER isn't executed in the same transaction context)? What I found is that the UPDATE TRIGGER was just never fired.

I assume it was never fired because it's outside the transaction and was therefore blocked - correct me if I'm wrong. Under what context is TRIGGER being executed? However, I'm seeing conflicting information:

A trigger is part of the transaction started by the statement that fired it. Thus, if the trigger fails the firing statement fails and is rolled back.

If this is true, why the hell my UPDATE TRIGGER never updated "acc"??
Reference: http://www.dotnetjohn.com/articles.aspx?articleid=133


Thanks in advance.
AnswerRe: Triggers and transaction context. Pin
Farhan Noor Qureshi27-Oct-05 9:21
Farhan Noor Qureshi27-Oct-05 9:21 
GeneralRe: Triggers and transaction context. Pin
devvvy27-Oct-05 13:49
devvvy27-Oct-05 13:49 
QuestionDatabase 'foodmart 2000' does not exist Pin
kuldeep_kumar27-Oct-05 5:25
kuldeep_kumar27-Oct-05 5:25 
QuestionDynamic procedures, are they possible? Pin
FruitBatInShades27-Oct-05 3:59
FruitBatInShades27-Oct-05 3:59 
AnswerRe: Dynamic procedures, are they possible? Pin
Colin Angus Mackay27-Oct-05 6:31
Colin Angus Mackay27-Oct-05 6:31 
AnswerRe: Dynamic procedures, are they possible? Pin
codet28-Oct-05 16:28
codet28-Oct-05 16:28 
QuestionProblems inserting data in database with datagrid Pin
wappi_berlin27-Oct-05 1:44
wappi_berlin27-Oct-05 1:44 
QuestionExcluding some fields from a table in a datagrid Pin
odrap26-Oct-05 0:24
odrap26-Oct-05 0:24 
AnswerRe: Excluding some fields from a table in a datagrid Pin
Edbert P26-Oct-05 12:50
Edbert P26-Oct-05 12:50 
QuestionInsert Data via Stored procedure by ado.net Pin
thedom225-Oct-05 23:33
thedom225-Oct-05 23:33 
AnswerRe: Insert Data via Stored procedure by ado.net Pin
Edbert P26-Oct-05 12:52
Edbert P26-Oct-05 12:52 
GeneralRe: Insert Data via Stored procedure by ado.net Pin
thedom226-Oct-05 13:16
thedom226-Oct-05 13:16 
QuestionCreating a Microsoft Acces &quot;Module&quot; in a MDB-file by Code from C++ Pin
Uwe Keim25-Oct-05 20:08
sitebuilderUwe Keim25-Oct-05 20:08 
AnswerRe: Creating a Microsoft Acces &quot;Module&quot; in a MDB-file by Code from C++ Pin
Uwe Keim25-Oct-05 20:33
sitebuilderUwe Keim25-Oct-05 20:33 
QuestionQuery Tables Fiels name and type Pin
icDavid25-Oct-05 13:12
icDavid25-Oct-05 13:12 
AnswerRe: Query Tables Fiels name and type Pin
icDavid25-Oct-05 14:27
icDavid25-Oct-05 14:27 
AnswerRe: Query Tables Fiels name and type Pin
Farhan Noor Qureshi25-Oct-05 17:59
Farhan Noor Qureshi25-Oct-05 17:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.