Error Executing Database Query: I want to create a custom error page for this error.

Discussion in 'Programming' started by JLG2, Mar 1, 2007.

  1. #1
    I'm getting the below error message. I know why I'm getting it. I just want to create a custom error page for viewers telling them what they have done and what they need to do. I created an ErrorValidation.cfm page and Application.cfc page (view also below). I put them in the same directory and I still get the generic message. Please advise.

    GENERIC ERROR MESSAGE:

    Error Occurred While Processing Request
    Error Executing Database Query.
    [Macromedia][SQLServer JDBC Driver][SQLServer]Violation of UNIQUE KEY constraint 'IX_tblEnrollments'. Cannot insert duplicate key in object 'tblEnrollments'.

    The error occurred in C:\Inetpub\wwwroot\hr\thanks.cfm: line 48

    46 : <cfquery name="insertRow" datasource="HRTraining">
    47 : INSERT INTO tblEnrollments (SessionNumber, EmployeeID, Attended)
    48 : VALUES (#Evaluate("form." & fieldName)#, #form.EmployeeID#, #form.Attended#);
    49 : </cfquery>
    50 : </cfif>
    --------------------------------------------------------------------------------

    SQL INSERT INTO tblEnrollments (SessionNumber, EmployeeID, Attended) VALUES (1021, 316, 0);
    DATASOURCE HRTraining
    VENDORERRORCODE 2627
    SQLSTATE 23000

    Please try the following:
    Check the ColdFusion documentation to verify that you are using the correct syntax.
    Search the Knowledge Base to find a solution to your problem.

    Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
    Remote Address 192.168.171.24
    Referrer http://169.147.175.120/hr/signup.cfm
    Date/Time 01-Mar-07 01:43 PM

    APPLICATION.CFC Page :

    <cfcomponent output="false">

    <cfset THIS.name = "ows19">
    <cferror type="Request" template="ErrorRequest.cfm">
    <cferror type="Exception" template="ErrorRequest.cfm">
    <cferror type="Validation" template="ErrorRequest.cfm">

    <cffunction name="onApplicationStart" returnType="boolean" output="false">
    <!--- When did the application start? --->
    <cfset APPLICATION.appStarted = now()>

    <cfreturn true>
    </cffunction>

    <cffunction name="onApplicationEnd" returnType="void" output="false">
    <cfargument name="appScope" required="true">

    <!--- Log how many minutes the application stayed alive --->
    <cflog file="#THIS.name#" text=
    "App ended after #dateDiff('n',ARGUMENTS.appScope.appStarted,now())# minutes.">

    </cffunction>

    <cffunction name="onRequestStart" returnType="boolean" output="true">
    <cfset request.dataSource = "hr">

    <cfreturn true>
    </cffunction>

    <cffunction name="onRequestEnd" returnType="void" output="true">

    </cffunction>

    <cffunction name="onError" returnType="void" output="false">
    <cfargument name="exception" required="true">
    <cfargument name="eventName" type="string" required="true">

    <!--- Use the cflog tag to record info on the error --->
    <cfif arguments.eventName is "">
    <cflog file="#THIS.name#" type="error"
    text="#arguments.exception.message#">

    <cfelse>
    <cflog file="#THIS.name#" type="error"
    text="Error in Method [#arguments.eventName#] #arguments.exception.message#">
    </cfif>

    <!--- Let the <cferror> tags do their job. --->

    <cfthrow object="#arguments.exception#">

    </cffunction>

    </cfcomponent>

    ErrorValidation.CFM PAGE:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html lang="en">
    <head>
    <title>ERROR!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="Author" content="Educational Technology">
    <meta name="Contact" content="edtech@kumc.edu">
    <meta name="Description" content="KU School of Medicine-Wichita Human Resources">
    <meta name="Keywords" content=
    "HR, human resources, employment, benefits, training, forms, policies, WHEAT, dean's council on recognition">
    <link href="stylens.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    @import url("style.css");
    .style2 {font-size: x-large}
    -->
    </style>

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
    }

    function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    </head>
    <body background="images/bghr.gif" onload=
    "MM_preloadImages('images/menu_staffb.gif','images/menu_calb.gif','images/menu_eob.gif','images/menu_benefitsb.gif','images/menu_eeb.gif','images/menu_policiesb.gif','images/menu_formsb.gif','images/menu_appb.gif')">

    <table width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
    <tr>
    <td width="196"><a href="#content"><img src="images/title_01.gif" alt="" width="196" height=
    "9" border="0"></a></td>
    <td width="111" bgcolor="#333366"><img src="images/title_02.gif" width="111" height="9" alt=
    ""></td>
    <td width="100%" bgcolor="#333366">
    <div align="right"><a name="top"></a><img src="images/title_03.gif" width="343" height="9" alt=""></div>
    </td>
    </tr>

    <tr>
    <td width="196"><a href="index.html"><img src="images/title_04.gif" alt="" width="196" height="73" border="0"></a></td>
    <td width="111" bgcolor="#FFFFFF"><a href="index.html"><img src="images/title_05.gif"
    alt="" width="111" height="73" border="0"></a></td>
    <td width="100%">
    <div align="right"><img src="images/title_06.jpg" width="343" height="73" alt=""></div>
    </td>
    </tr>

    <tr>
    <td width="196"><a href="http://wichita.kumc.edu/"><img src="images/title_07.gif" alt="" width="196" height="20" border="0"></a></td>
    <td width="111" bgcolor="#333366"><a href="http://wichita.kumc.edu/"><img src="images/title_08.gif"
    alt="" width="111" height="20" border="0"></a></td>
    <td width="100%" bgcolor="#333366">
    <div align="right"><img src="images/title_09.gif" alt="" width="343" height="20" border="0"
    usemap="#Map"></div>
    </td>
    </tr>

    <tr>
    <td width="196"><img src="images/title_10.gif" width="196" height="11" alt=""></td>
    <td width="111" bgcolor="#993300"><img src="images/title_11.gif" width="111" height="11"
    alt=""></td>
    <td width="100%" bgcolor="#993300">
    <div align="right"><img src="images/title_12.gif" width="343" height="11" alt=""></div>
    </td>
    </tr>

    <tr>
    <td width="196"><img src="images/title_13.gif" width="196" height="6" alt=""></td>
    <td width="111" bgcolor="#333366"><img src="images/title_14.gif" width="111" height="6" alt=
    ""></td>
    <td width="100%" bgcolor="#333366">
    <div align="right"><img src="images/title_15.gif" width="343" height="6" alt=""></div>
    </td>
    </tr>

    <tr>
    <td width="196"><img src="images/title_16.gif" width="196" height="8" alt=""></td>
    <td width="111"><img src="images/title_17.gif" width="111" height="8" alt=""></td>
    <td width="100%">
    <div align="right"><img src="images/title_18.gif" width="343" height="8" alt=""></div>
    </td>
    </tr>

    <tr>
    <td width="196"><img src="images/title_19.gif" width="196" height="7" alt=""></td>
    <td width="111" bgcolor="#993300"><img src="images/title_20.gif" width="111" height="7" alt=
    ""></td>
    <td width="100%" bgcolor="#993300">
    <div align="right"><img src="images/title_21.gif" width="343" height="7" alt=""></div>
    </td>
    </tr>

    <tr>
    <td><img src="images/title_22.gif" width="196" height="4" alt=""></td>
    <td width="111" bgcolor="#333366"><img src="images/title_23.gif" width="111" height="4" alt=
    ""></td>
    <td width="100%" bgcolor="#333366">
    <div align="right"><img src="images/title_24.gif" width="343" height="4" alt=""></div>
    </td>
    </tr>

    <tr>
    <td><img src="images/title_25.gif" width="196" height="6" alt=""></td>
    <td width="111" bgcolor="#333366"><img src="images/title_26.gif" width="111" height="6" alt=
    ""></td>
    <td width="100%" bgcolor="#333366">
    <div align="right"><img src="images/title_27.gif" width="343" height="6" alt=""></div>
    </td>
    </tr>

    <tr>
    <td width="196" valign="top"><img src="images/menuhr2.gif" alt="" name="menu" width="196"
    height="323" border="0" usemap="#menuMap" id="menu">
    <map name="menuMap">
    <area shape="rect" coords="22,0,74,19" href="staff/index.html" alt="HR Staff" onMouseOver=
    "MM_swapImage('menu','','images/menu_staffb.gif',1)" onMouseOut="MM_swapImgRestore()">
    <area shape="rect" coords="22,19,113,42" href="http://calendar.kusmw.kumc.edu" alt="Wichita Calendar"
    onMouseOver="MM_swapImage('menu','','images/menu_calb.gif',1)" onMouseOut=
    "MM_swapImgRestore()">
    <area shape="rect" coords="22,42,175,68" href="jobs/index.html" alt=
    "Employment Opportunities" onMouseOver="MM_swapImage('menu','','images/menu_eob.gif',1)"
    onMouseOut="MM_swapImgRestore()">
    <area shape="rect" coords="22,68,76,92" href="benefits/index.html" alt="Benefits"
    onMouseOver="MM_swapImage('menu','','images/menu_benefitsb.gif',1)" onMouseOut=
    "MM_swapImgRestore()">
    <area shape="rect" coords="22,92,158,117" href="training/index.html" alt=
    "Learning and Development" onMouseOver="MM_swapImage('menu','','images/menu_eeb.gif',1)"
    onMouseOut="MM_swapImgRestore()">
    <area shape="rect" coords="23,117,144,141" href="policies/index.html" alt="Policies and Procedures"
    onMouseOver="MM_swapImage('menu','','images/menu_policiesb.gif',1)" onMouseOut=
    "MM_swapImgRestore()">
    <area shape="rect" coords="23,141,76,168" href="forms/index.html" alt="Forms" onMouseOver=
    "MM_swapImage('menu','','images/menu_formsb.gif',1)" onMouseOut="MM_swapImgRestore()">
    <area shape="rect" coords="23,168,182,204" href="appreciation.html" alt="Appreciation and Recognition Council" onMouseOver=
    "MM_swapImage('menu','','images/menu_appb.gif',1)" onMouseOut="MM_swapImgRestore()">
    </map>
    </td>
    <td colspan="2" rowspan="2" valign="top">
    <table width="100%" border="0" cellpadding="14" cellspacing="0" summary="">
    <tr>
    <td>
    <h1><a name="content"></a> <span class="style2">Input Error!</span></h1>
    <h2> <span class="martext">Be aware you are attempting to register for a class you are already registered for. Please return to the form and try again. If you continue to have problems please contact the Human Resource department at 293-2615 </span><br>
    </h2>

    #ERROR.invalidFields#

    <p class="textright"> <a href="#top">Top ^</a></p>
    <p class="graybar"><a href="index.html">HR Home Page</a> &gt;<br>
    </p>
    </td>
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td><img src="images/title_30c.gif" width="196" height="2" alt=""></td>
    </tr>

    <tr>
    <td valign="top">&nbsp;</td>
    <td colspan="2">
    <hr size="1">
    <p class="center"><a href="staff/index.html">HR Staff</a> | <a href="http://calendar.kusmw.kumc.edu">Wichita Calendar</a> |
    <a href="jobs/index.html">Employment Opportunities</a><br>
    <a href="benefits/index.html">Benefits</a> | <a href="training/index.html">Learning &amp; Development</a> | <a href="policies/index.html">Policies &amp; Procedures</a> | <a href="forms/index.html">
    Forms</a><br>
    <a href="appreciation.html">Appreciation and Recognition Council</a> <br>
    <a href="search.html">Search</a> | <a href="sitemap.html">Site Map</a> | <a href="contact.html">Contact</a> | <a href="index.html">Home</a></p>

    <p class="center"><a href="http://wichita.kumc.edu"><img src="images/kuwbtn.gif" alt="KU School of Medicine-Wichita" width="120"
    height="45" border="0"></a> <a href="index.html"><img src="images/btnhr.gif" alt=
    "Human Resources Home" width="120" height="45" border="0"></a></p>

    <p class="center">Page last updated: <!-- #BeginDate format:Am1 -->February 19, 2007<!-- #EndDate -->
    <br>
    For more information, contact: <a href="mailto:wichr@kumc.edu">Human Resources</a><br>
    Site questions and comments, contact: <a href="mailto:edtech@kumc.edu">Web Development
    Unit</a><br>
    <a href="http://wichita.kumc.edu/disclaimer">Copyright &copy; 1997-2005</a>, <a href=
    "mailto:kusmw@kumc.edu">KU School of Medicine - Wichita</a></p>
    </td>
    </tr>
    </table>
    <blockquote>
    <hr><font size="-1" color="gray">#ERROR.Diagnostics#</font>
    </blockquote>
    <map name="Map">
    <area shape="rect" coords="203,2,247,22" href="sitemap.html" alt="Site map">
    <area shape="rect" coords="251,2,296,22" href="contact.html" alt="Contact">
    <area shape="rect" coords="299,2,343,22" href="index.html" alt="Home">
    </map>
    </body>
    </html>
     
    JLG2, Mar 1, 2007 IP
  2. OneWebAve

    OneWebAve Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can specify the error page for the entire server in the CF administrator. If you have multiple sites, just do an include to your specific code based on the URL.
     
    OneWebAve, Mar 4, 2007 IP
  3. JLG2

    JLG2 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for replying.

    How would I do that?
     
    JLG2, Mar 5, 2007 IP
  4. OneWebAve

    OneWebAve Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    1. Go to your cfide/administrator folder
    2. Log in
    3. Click Settings
    4. Scroll down

    You will see two fields: Missing Template Handler and Site-wide Error Handler. You can specify the page you want to run when there is an error in those locations. Just make a page a stick in on your site. :)
     
    OneWebAve, Mar 6, 2007 IP