0
votes

I have a .cfm and .cfc that I am using to edit data in a cfgrid on the .cfm, and it works, however 10% of the time I will get the following error message:

"Error invoking CFC /test/editCFgrid.cfc: Internal Server Error"

I tried using the debugging advice, however no luck.

Here is the CFM code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<cfform name="artistform">
            <cfgrid format="html" name="artistgrid" pagesize=11
            striperows="yes" 
            bind="cfc:editCFgrid.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
            delete="yes" insert="yes" selectmode="edit"
            onchange="cfc:editCFgrid.saveArtist({cfgridaction},{cfgridrow},{cfgridchanged})">
                <cfgridcolumn name="firstname" header="First Name" />
                <cfgridcolumn name="lastname" header="Last Name" />
                <cfgridcolumn name="address" header="Address" />
                <cfgridcolumn name="city" header="City" />
                <cfgridcolumn name="state" header="State" />
                <cfgridcolumn name="postalcode" header="Postal Code" />
                <cfgridcolumn name="email" header="Email" />
                <cfgridcolumn name="phone" header="Phone" />
                <cfgridcolumn name="fax" header="Fax" />
                <cfgridcolumn name="thepassword" header="Password" />
</cfgrid>
</cfform>
</body>
</html>

Here is the CFC code:

<cfcomponent output="FALSE">
    <cffunction name="getArtists" hint="I extract artists from the database" access="remote" output="FALSE" returntype="struct">
        <cfargument name="page" required="TRUE" hint="the page the grid is on" />
        <cfargument name="pagesize" required="TRUE" hint="records displayed per page" />
        <cfargument name="gridsortcolumn" required="TRUE" hint="selected column to sort" />
        <cfargument name="gridsortdirection" required="TRUE" hint="the sort direction" />
        <cfset var qArtists = "" />

        <cfif arguments.gridsortcolumn eq "">
            <cfset arguments.gridsortcolumn = "lastname" />
            <cfset arguments.gridsortdirection = "asc" />
        </cfif>

            <cfquery name="qArtists" datasource="test_database">
                SELECT *
                FROM Artists
                ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
            </cfquery>

        <cfreturn QueryConvertForGrid( qArtists, arguments.page, arguments.pagesize ) />
    </cffunction>

    <cffunction name="saveArtist" type="any" hint="I insert, update or delete an artist" access="remote" output="FALSE" returntype="void">
        <cfargument name="gridaction" type="any" required="TRUE" hint="I for insert, U for update and D for delete" />
        <cfargument name="gridrow" type="any" required="TRUE" hint="the rows being inserted or updated" />
        <cfargument name="gridchanged" type="any" hint="the changes" />
        <cfset var qInsertArtist = "" />
        <cfset var qUpdateArtist = "" />
        <cfset var qDeleteArtist = "" />

        <cfif IsStruct( arguments.gridrow ) and IsStruct( arguments.gridchanged )>
            <cfif arguments.gridaction eq "I">
                <cfquery name="qInsertArtist" datasource="test_database">
                    INSERT INTO Artists
                        (firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
                    VALUES
                        (<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.firstname#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.lastname#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.address#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.city#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.state#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.postalcode#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.email#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.phone#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.fax#" />, 
                        <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.thepassword#" />)
                </cfquery>

            <cfelseif arguments.gridaction eq "U">
                <cfset var colname = StructKeyList( arguments.gridchanged ) />
                <cfset var value = StructFind( arguments.gridchanged, colname ) />
                    <cfquery name="qUpdateArtist" datasource="test_database">
                        UPDATE Artists
                        SET #colname# = <cfqueryparam value="#value#" />
                        WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
                    </cfquery>

            <cfelseif arguments.gridaction eq "D">
                <cfquery name="qDeleteArtist" datasource="test_database">
                DELETE FROM Artists 
                WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
                </cfquery>
            </cfif>
        </cfif>
    </cffunction>
</cfcomponent>

Each function (edit, insert, delete, etc) works, but it randomly will generate the error. Ultimately, I am seeking a code that will ignore/block/"OK" the error message so the user won't see it.

Any help will be greatly appreciated! I have spent the entire day (9 hours) googling for an answer, but I haven't found any. I do not have access to the CF Admin Log, I'm just a regular developer. Thanks!

3
try setting your own global error handler - help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/…Henry
It'd've been really great if whoever voted this down explained why they decided to do so. Simply downvoting is not very helpful. Voting it back up as there's nothing wrong with the question that a bit of polish wouldn't help.Adam Cameron
You should be able to see the actual error by just browsing to the URL of the erroring request (the full URL should display in the Firebug network panel). Failing that, it'll be in the exception log or application log or out log depending on various things that I've never quite determined. Post the actual error message, and we can work out what's up.Adam Cameron
Here are some tips regarding debugging CFCs. Essentially, enable robust debugging, check your logs, use cfinvoke to repeatedly call your method and log those results. Hopefully that help you see what's going on.Barry
Thank you @AdamCameron for voting this issue up one. Here is the error I get from Firebug: "NetworkError: 500 Server Error - server.com/test/editCFgrid.cfc"Enchauva

3 Answers

1
votes

Google chrome, firebug in firefox, IE developer tools can all help you with this.

In google chrome (my preference), right click on your page > inspect element. Then go to the network tab. You'll have to refresh your web page. Then you will see your cfc in the list of files (probably RED). Right click > open in new tab, and you'll open the cfc directly with all the arguments being called. You should then be able to see your error.

There is no ignore/block/ok. You need to fix the error.

0
votes

Perhaps a time out or a SQL error. To get the full error use: cferror, this tag show a full debug information (better than debug server info) I sent it to me by mail:

Put this on you Application file:

<cferror type="exception" template="error.cfm" />
<cferror type="request" template="error.cfm" />

Create a "error.cfm" file with:

"Error message"
<cfsavecontent variable="errorContent">
<cfoutput>
An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />

<h2>Error:</h2>
<cfdump var="#error#" label="Error">
<h2>Form:</h2>
<cfdump var="#form#" label="Form">
<h2>URL:</h2>
<cfdump var="#url#" label="URL">
<h2>SESSION:</h2>
<cfdump var="#SESSION#" label="SESSION">

</cfoutput>
</cfsavecontent>

<cfmail to="[email protected]" from="[email protected]" subject="Error on #cgi.server_name#: #error.message#" type="html">
#errorContent#
</cfmail>
0
votes

There is a way to ignore/block/ok the "error" message with the following script:

<script>ColdFusion.setGlobalErrorHandler(function (error) 
{mygrid = ColdFusion.Grid.refresh ('artistgrid', false);
}
);
</script>

Insert this script in the CFM files, and you're good to go! Being that the error that I was encountering was not impacting the function (editing the cells) of the cfgrid (the pop-up message was being more of a nuisance then anything else). Hopefully this solution will help others!

You do not need to use the 'Grid.refresh' command in the script, you can use anything command you want.

Thanks everyone who attempted to answer my issue!