View Single Post
  #4 (permalink)  
Old January 18th, 2008, 07:24
ianlo ianlo is offline
Senior Member and Blogger
 
Join Date: Dec 2006
Location: Singapore
Posts: 149
Blog Entries: 5
Thanks: 5
Thanked 11 Times in 10 Posts
Groans: 0
Groaned at 1 Time in 1 Post
Rep Power: 2
ianlo is on a distinguished road
Send a message via AIM to ianlo Send a message via Skype™ to ianlo
Re: Direct SQL Update in Agent. When is it committed?

Quote:
Originally Posted by jlgottlieb View Post
Hi,

The agent terminates when the exception occurs, but when checking the Shipment_Refnum table, I see that all the refnums that I deleted are still there. I would have expected the deleted refnums to be gone and only the ones after the failed insert to be missing. That does not seem to be the case.

When are the Direct Sql Updates persisted to the database? If the agent fails, are all updates rolled back?

I'm thinking of rewriting the agent to either just update, rather than delete and insert or to write this as a stored procedure to be called instead. I would appreciate any comments as to which is the better way to accomplish this.
Hi jlgottlieb

It is my practice to always use stored procedures when doing CUD operations. Only for Select statements do I enter it directly in the DirectSQL agent actions.

I found out that although through experience each DirectSQL statement is committed independently, unless we can verify this in the code, it is a risky assumption. Also there is the complexity of multiple agents possibly executing the DirectSQL in parallel...

So at least for me the general rule is this:

1) CUD statements are all executed in stored procedures as a single logical business operation.
2) No COMMITS or ROLLBACKS in the stored procedures
3) Use as few cursors as possible in the stored procedures and when using cursors I always specify EXPLICIT cursors

In addition, to optimise DirectSQL agent actions:
1) If there are multiple SELECT statements with CUD operations needed, all this goes into a single stored procedure
2) Multiple SELECT statements (unless each returning a different result) are collapsed if possible into a SINGLE select statement.
3) Try to push ALL CRUD database operations to the database by way of stored procedures or fuctions - this is to reduce the data round trip required between the application server and DB server.

Hope this helps!

Ian
Reply With Quote