Hi, I'm working with a DBA on a project. During the course of the project he suggested that updating "Status" field of "ItemRequest" entity would fire a trigger, which in turn, perform further updates (ie. calculate balances... etc).
Code:
Class ItemRequest
... other stuff ...
Public Property Status As Int16
...
End Property
... other stuff ...
End Class
In client code:
Code:
Protected Sub UpdateRequestStatus()
Dim req As ItemRequest
Dim sess As ISession
Dim trx As ITransaction
sess = GetSession()
trx = sess.BeginTransation()
req = GetRequest()
req.RequestedAmount = 12345
req.Status = COMMIT_REQ
sess.Update(req) 'Update database -- in turn fires trigger
trx.Commit()
End Sub
Thing is, we need to rollback transaction if "acc balance" < 12345, then inform user "Insufficient funds in account".
How can I get this information from trigger?? How should this be implemented...?? I was thinking (hopefully not), that the only course available is
RAISERROR() from within my TSQL trigger...
Code:
Protected Sub UpdateRequestStatus()
Dim req As ItemRequest
Dim sess As ISession
Dim trx As ITransaction
sess = GetSession()
trx = sess.BeginTransation()
req = GetRequest()
req.RequestedAmount = 12345
req.Status = COMMIT_REQ
Try
sess.Update(req) 'Update database -- in turn fires trigger
trx.Commit()
Catch ex As SqlException '[b]RAISERROR[/b] from within [b]TSQL [/b]trigger
'If insufficient balance, inform user...
End Try
End Sub
Any pointer?? Thanks in advance, any suggestion would be greatly appreciated!