?
Solved

proper use of <cftransaction> with <cftry> and <cfcatch>

Posted on 2005-03-30
7
Medium Priority
?
1,275 Views
Last Modified: 2013-12-24
It may seem that I am splitting hairs but I would like to get people's opinion on this.  While I am almost sure that both structures below are practically the same I wouldn't be able to say which is more correct.  Should you put a <cftransaction> inside a <cftry> or the other way around?  Are they exactly the same or can there be a case when they are not?

<CFTRANSACTION ACTION="BEGIN">
   <CFTRY>
     <!---cfquery NO:1--->

     <!---cfquery NO:n..n.n--->

   <CFCATCH type="Database">
      <cftransaction Action="Rollback"/>
      <CFABORT showerror="There was an error saving your data: #CFCATCH.Message#: #CFCATCH.Detail#">
   </cfcatch>
   </cftry>
</cftransaction>


<CFTRY>
   <CFTRANSACTION>
      <!---cfquery NO:1--->

      <!---cfquery NO:n..n.n--->
   </CFTRANSACTION>

   <CFCATCH type="Database">
      <cftransaction Action="Rollback"/>
      <CFABORT showerror="There was an error saving your data: #CFCATCH.Message#: #CFCATCH.Detail#">
   </cfcatch>
</CFTRY>
0
Comment
Question by:bisonfur37
[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
7 Comments
 
LVL 17

Accepted Solution

by:
Tacobell777 earned 672 total points
ID: 13667588
Personally I put the transaction outside the cftry, but they both work the same...
0
 
LVL 14

Assisted Solution

by:Renante Entera
Renante Entera earned 664 total points
ID: 13669242
Hi bisonfur37!

You may refer on the following livedocs to have a clear understanding of what really its usage :

1.  <cftry> - http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-c18.htm#wp1104557
2.  <cfcatch> - http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-a10.htm#wp3395038
3.  <cftransaction> - http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-c15.htm#wp1104164

Hope this helps you.


Regards!
eNTRANCE2002 :-)
0
 
LVL 2

Author Comment

by:bisonfur37
ID: 13672364
Great tips, actually I had already read those.  The question still remains.  How do you properly use <CFTRANSACTION> with <CFTRY> and <CFCATCH> to provide the most user friendly errors?  <CFTRANSACTION> does a great job of not messing things up on the dB side.  Now, I just want to provide the user with nice messages should things go South.  I am almost positive that the syntax would be as follows:

<CFTRY>
   <CFTRANSACTION>
      <!---cfquery NO:1--->

      <!---cfquery NO:n..n.n--->
   </CFTRANSACTION>

   <CFCATCH type="Database">
      <cftransaction Action="Rollback"/>
      <CFABORT showerror="There was an error saving your data: #CFCATCH.Message#: #CFCATCH.Detail#">
   </cfcatch>
</CFTRY>

And that you would most likely want to have a single <CFTRANSACTION> within a <CFTRY>.  Does anyone have anything to say about this?  Does anyone see anything wrong, or at least not efficient/recommended, with having multiple <CFTRANSACTIONS> within <CFTRY>?
0
 
LVL 21

Assisted Solution

by:pinaldave
pinaldave earned 664 total points
ID: 13672601
Personally I will do same as TacoBell.
Both are same and will have same effect. Very interesting Q. I think they are same thing. (What a Q? There is nothing Experts can think of. good one!)
Regards,
---Pinal
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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