Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
RayBees #1
CFTRANSACTION not rolling back
Greetings
I am performing a series of deletes from several tables and one selection. It
does catch the an error however, it commits all the deletes exception the one
that threw the error. Why?
Here is the mock up of my code:
<CFSET Commit = "Yes">
<CFSET errCount = 0>
<CFSET arrErrorMessage = ArrayNew(1)>
<CFTRANSACTION action="begin">
<!--- Get FSubFeatureID form CS_SubServices table used to detetmine if a
section has contact information --->
<CFTRY>
<CFQUERY name="GetAllSubServiceID" DATASOURCE="DSN">
SELECT
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to retrieve SubServiceID from
table1. Please contact webmaster.">
</CFCATCH>
</CFTRY>
<!---
************************************************** ******************************
******* --->
<!--- ************************** DELETE FROM ADMIN TABLES
**************************** --->
<!---
************************************************** ******************************
******* --->
<CFIF GetAllSubServiceID.recordcount GT 0>
<CFOUTPUT query="GetAllSubServiceID">
<CFTRY>
<CFQUERY name="DeleteFeatures" Datasource="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table2. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
</CFOUTPUT>
</CFIF>
<CFTRY>
<CFQUERY NAME="DeleteSections" DATASOURCE="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table3. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
<CFTRY>
<CFQUERY name="DeleteLinks" Datasource="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table4. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
<CFTRY>
<CFQUERY name="DeleteService" Datasource="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table5. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
<!---
************************************************** ******************************
******* --->
<!--- ************************* DELETE FROM PUBLIC TABLES
**************************** --->
<!---
************************************************** ******************************
******* --->
<CFIF GetAllSubServiceID.recordcount GT 0>
<CFOUTPUT query="GetAllSubServiceID">
<CFTRY>
<CFQUERY name="DeletePROD_Features" Datasource="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table5. Please
contact ">
</CFCATCH>
</CFTRY>
</CFOUTPUT>
</CFIF>
<CFTRY>
<CFQUERY NAME="DeletePROD_Sections" DATASOURCE="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table6. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
<CFTRY>
<CFQUERY name="DeletePROD_Links" Datasource="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table7. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
<CFTRY>
<CFQUERY name="DeletePROD_Service" Datasource="DSN">
DELETE
</CFQUERY>
<CFCATCH type="database">
<CFSET Commit = "No">
<CFSET errCount = errCount + 1>
<CFSET arrErrorMessage[errCount] ="Unable to delete from table8. Please
contact webmaster.">
</CFCATCH>
</CFTRY>
</CFTRANSACTION>
<CFIF Commit EQ "Yes">
<CFTRANSACTION action="commit" />
<CFLOCATION url="index.cfm?fuseaction=ServicesGuide">
<CFELSE>
<CFTRANSACTION action="rollback" />
<CFINCLUDE template="dsp_ErrorMessage.cfm">
</CFIF>
RayBees Guest
-
Coldfusion MX 5 log rolling
Hi We use coldfusion mx 5.0. I dont see automatic log rolling options. Is there a way we can automate the log rolling.. Thanks -
Rolling out Flash Player
Hi. I have to roll out Flash Player 9 to about 200 workstations in our office. Is there any way this can be done via a Group Policy in a Windows... -
Rolling back Hot Fix 2/CFMXE7
1. Open ColdFusion Administrator 2. Click 'System Information' 3. Make note of the path of CHF7010002.jar (i.e.... -
rolling your own AOP
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ... -
Incrementing a value on a rolling basis
Hi, I'm thinking this should be easy but I can't figure out a way to do this without using DTS, SPROC or trigger. I have a table that contains... -
OldCFer #2
Re: CFTRANSACTION not rolling back
The trouble is you are error handling all problems then continuing to do
deletes. You should
structure your cftransaction something like this. It's much simpler:
<cfset progressMsg = "">
<cftransaction action="begin">
<cftry>
Run Select query
<cfset progressmsg = "Select OK">
Run Delete 1
<cfset progressmsg = "Delete 1 OK">
Run Delete 2
...........
<cfcatch type="database">
<cftransaction action="rollback"/>
#Progressmsg#
</cfcatch>
</cftransaction>
Now the first time a DB error occurs, it jumps to the catch block and rolls
everything back.
BTW the
<CFIF Commit EQ "Yes">
<CFTRANSACTION action="commit" />
in your code doesn't do anything. SInce it follows the closing
</cftransaction> commits
or rollbacks have already been done. You can't do anything at this point.
OldCFer Guest



Reply With Quote

