Chad:

Put the CFTRY inside the CFTRANSACTION block.  Also, two CFCATCH blocks
aren't needed in that code.  The commitIt flag isn't really needed also
unless you want it for something else outside the block.  So, something like
this will work:

<CFTRANSACTION ACTION="BEGIN">
        <CFTRY>
                <----------------------------------------------------------------------
                Initialize commitIt to Yes.
                
----------------------------------------------------------------------->
            <CFSET commitIt = "Yes">
            <CFQUERY NAME='makeNewCourse' DATASOURCE='cfsnippets'>
            INSERT INTO Courses
                (Number, Descript)
            VALUES
                ('#myNumber#', '#myDescription#')
            </CFQUERY>

            <CFQUERY NAME='insertNewCourseToList' DATASOURCE='cfsnippets'>
            INSERT INTO CourseList
                (CorNumber, CorDesc, Dept_ID,
                CorName, CorLevel, LastUpdate)
            VALUES
                ('#myNumber#', '#myDescription#', '#myDepartment#',
                '#myDescription#', '#myCorLevel#', #Now()#)
            </CFQUERY>

        <CFTRANSACTION ACTION="COMMIT"/>

    <!------------------------------------------------------------------
    Rolls back the pending insertion if database exception is caught.
    ------------------------------------------------------------------->
    <CFCATCH TYPE="DATABASE">
        <CFTRANSACTION ACTION="ROLLBACK"/>
        <CFSET commitIt = "No">
    </CFCATCH>

    </CFTRY>

</CFTRANSACTION>


Maybe it's useful, maybe not.  Have fun...

Regards,
Joel Parramore


> -----Original Message-----
> From: Chad Gray [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 25, 2001 10:20 AM
> To: CF-Talk
> Subject: CFTRANSACTION error in CF example
>
>
> There is an error in the example code that comes with the CFStudio help
> file for CFTRANSACTION. I get this error: Context validation error in tag
> CFTRY The tag is not correctly positioned relative to other tags in the
> template: the last tag nested inside tag CFTRY must be a CFCATCH tag.
> Currently it is a CFTRANSACTION tag. The error occurred while
> processing an
> element with a general identifier of (CFTRY), occupying document position
> (27:1) to (27:7). How would i fix the code so it works right?
>
> CFTRANSACTION Example
>
>
> CFTRANSACTION can be used to group multiple queries using CFQUERY into a
> single business event. Changes to data requested by these queries can be
> committed on the basis of the success or failure of the query by
> using the
> actions COMMIT and ROLLBACK, respectively.
>
> The following is a sample listing (see code in right pane):       INSERT
> INTO Courses (Number, Descript) VALUES ('#myNumber#',
> '#myDescription#')              INSERT INTO CourseList
> (CorNumber, CorDesc,
> Dept_ID, CorName, CorLevel, LastUpdate) VALUES ('#myNumber#',
> '#myDescription#', '#myDepartment#', '#myDescription#', '#myCorLevel#',
> #Now()#)
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to