我正在使用cftransaction标签,当错误来临时,它没有回滚条目,我不确定有什么问题,我没有使用cftransaction的嵌套部分,简单的一个不工作,我是不确定嵌套在这里的表现如何,如果错误的话,请更正我的代码...
<cffunction access="public" name="newRegistration" returntype="any">
<cfargument name="structform" default="" required="no" type="struct">
<cfset var newregis = "">
<cfset var str = "">
<cfset var msg = "">
<cftry>
<cftransaction action="begin"/>
<cfquery name="newregis" result="lastGenerated">
--- Insert Goes Here ---
</cfquery>
<cfset rsLastID = lastGenerated.generated_key>
<cfif isDefined('arguments.structform.mailoption') AND arguments.structform.mailoption EQ 'Yes'>
<cfset msg = createAccountEmail(rsLastID,'nar')>
</cfif>
<cftransaction action="commit"/>
<cfset str = "Account Created Successfully. #msg#">
<cfcatch type="any">
<cftransaction action="rollback"/>
<cfset str = "Error! #cfcatch.Detail# #cfcatch.Message#. Entry rolled back, try again">
</cfcatch>
</cftry>
<cfreturn str>
</cffunction>
答案 0 :(得分:3)
您似乎缺少关闭的CFTRANSACTION标记,该标记应该包含在try / catch块中。
<cftransaction action="begin">
<cftry>
...
<cfcatch type="any">
<cftransaction action="rollback" />
...
</cfcatch>
</cftry>
</cftransaction>
使用那种结构,你应该很好。