1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Have you seen this error?

Discussion in 'Programming' started by unitedlocalbands, Nov 17, 2007.

  1. #1
    Code (Text):
    1.  
    2. Error Executing Database Query.  
    3. [Macromedia][SQLServer JDBC Driver]Connection reset by peer: socket write error  
    4.  
    Have you seen this error, Does this mean that there is something wrong with my programing or do I just need to add error handeling to my application file?

    If so what might the error handeling look like.

    And how can I send the error to me via email.

    thanks a bunch?
     
    unitedlocalbands, Nov 17, 2007 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No. I haven't seen that error. I'm sure you've googled it and found it turns up a few links though not many answers. One interesting mention was this post

    http://www.mail-archive.com/dev@lists.cfdeveloper.co.uk/msg16558.html

    There are also a few mentions of problems with 6.1, possibly driver related. But again, nothing conclusive. What versions of CF/MS SQL + SP are you using? Does the error go away or are you experiencing any other problems?

    There are different options for handling errors. The simplest is a cftry/cfcatch. I.e. cfcatch type="database" errors and inside the <cfcatch> block, use <cfmail ...> to send yourself the error message. But you should also review these sections to decide what is the best method for you.

    Determining error-handling strategies
    http://livedocs.adobe.com/coldfusion/7/htmldocs/00001137.htm
    http://livedocs.adobe.com/coldfusion/7/htmldocs/00001138.htm#1096230
     
    cfStarlight, Nov 17, 2007 IP
  3. unitedlocalbands

    unitedlocalbands Peon

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am working on my error handling for a file upload. I'm having a hard time under standing what type of error handling I need.

    I just need to ckeck if the user has selected a file with the correct "mime type"

    Here is the error I'm trying to catch.

    Code (Text):
    1.  
    2. The MIME type of the uploaded file "application/octet-stream" was not accepted by the server.  
    3.  
    4. Only files of type "audio/mpeg, audio/x-mpeg" can be uploaded.
    5. Verify that you are uploading a file of the appropriate type.  
    6.  
    I started by using the "exception" but Im not sure what kind of error this is.

    here is the cferror tag

    Code (Text):
    1.  
    2. <cferror type="exception" mailto="jamescreston@sbcglobal.net" template="error_exception.cfm"
    3. exception="application">
    4.  
    Here is the vailidation code to make sure they selected a file from their computer, or that they have filled in the form field.

    Code (Text):
    1.  
    2. <cfoutput>
    3. <cfif isdefined("form.upload_now")>
    4.  
    5. <CFIF IsDefined("Form.ul_path")>
    6.     <CFSET ul_path = "#Form.ul_path#">
    7. <CFELSE>   
    8.     <CFSET ul_path = "">
    9. </CFIF>
    10.  
    11. <CFSET Valid = true>
    12. <CFSET Error = "">
    13.  
    14. <cfif len(#form.ul_path#) LTE 0>
    15. <CFSET Error = Error & "Please select an mp3.<BR>">
    16. <CFSET Valid = False>
    17.  
    18. </cfif>
    19.  
    20.  
    21.  
    22. <CFIF not Valid>
    23.         <STRONG>Sorry, An error occurred</STRONG>
    24.         <HR>
    25.         <CFOUTPUT><font size="+1" color="660000">#Error#</font></CFOUTPUT>
    26.         <EM>Please correct the error/errors</EM><br>
    27.         <A HREF="javascript:history.go(-1)"><br>Click Here To Return</A>
    28.  
    29. </p>
    30.                            
    31.                
    32.                </div>
    33.                <!-- End contenthome -->
    34.                
    35.                <div id="rightcolumnhome"></div>
    36.                
    37.          </div>    
    38.          <!-- End Faux Columns -->
    39.  
    40.          <!-- Begin Footer -->
    41.          <div id="footer">
    42.                
    43.                <cfmodule template="sitefooter.cfm">
    44.          </div>
    45.          <!-- End Footer -->
    46.          
    47.    </div>
    48.    <!-- End Wrapper -->
    49. </body>
    50. </html>    
    51.        
    52.         <cfabort>
    53. <CFELSE>
    54.  
    55. <cfset uploadPath = GetDirectoryFromPath(GetTemplatePath()) & "#HELLO.USER_LOGINID##HELLO.USERID#\">
    56.   <cfif not DirectoryExists(uploadPath)>
    57.     <cfdirectory action="create" directory="#uploadPath#">
    58.   </cfif>
    59.  
    60.  
    61. <cffile accept="audio/mpeg, audio/x-mpeg" action="upload"
    62. destination="#uploadPath#" filefield="ul_path"  nameconflict="makeunique">
    63.  
    64.  
    65. <strong>YOUR SONG WAS UPLOADED SUCCESSFULLY!
    66. <cfset fileuploadpath = GetFileFromPath(cffile.ServerFile)>
    67. <a href="savepath.cfm?uploadpath=<cfoutput>#HELLO.USER_LOGINID##HELLO.USERID#</cfoutput>\<cfoutput>#fileuploadPath#</cfoutput>">
    68. <font size="+2" color="##FFFF33">CLICK HERE TO FINNISH</font></a></strong>
    69.  
    70. </CFIF>
    71. </cfif>
    72. </CFoutput>
    73.  
    If they did select a file from the computer and filled in the form field then it will pass the file to this tag

    Code (Text):
    1.  
    2. <cffile accept="audio/mpeg, audio/x-mpeg" action="upload"
    3. destination="#uploadPath#" filefield="ul_path"  nameconflict="makeunique">
    4.  
    Here is where the error happens if they selected a file with the incorect mime type. Then you see the ulgy coldfusion error page.

    So how do I dress this error page up or maybe There is a way to just add to the form vailidation script to make sure the correct file extesion is there before it is submited to the cffile tag.
     
    unitedlocalbands, Nov 17, 2007 IP
  4. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    No, you can't accurately check the file extension before the upload without using a signed applet, activeX control, etc. Its a security restriction built into browsers, which is a good thing. If that restriction didn't exist, any web site you visit could read the files on your hard drive. Not a good thing.

    For that type of error, I would just use a cftry/cfcatch. Because its expected that someone is going to try and upload the wrong file type. As for the type of exception to catch, a good place to look is the first line of the stack trace. It will give you the name of the exception class

    Code (Text):
    1.  
    2. [b]coldfusion.tagext.io.FileTag$InvalidUploadTypeException[/b]: The MIME type of the uploaded file "application/pdf" was not accepted by the server.
    3.  
    Then all you need to do is use it in your cfcatch

    Code (Text):
    1.  
    2.     <cftry>
    3.         <cffile accept="audio/mpeg, audio/x-mpeg" action="upload"
    4.             destination="#uploadPath#" filefield="ul_path"  nameconflict="makeunique">
    5.    
    6.         <cfcatch type="coldfusion.tagext.io.FileTag$InvalidUploadTypeException">
    7.             Sorry, that file type is not allowed.
    8.         </cfcatch>
    9.     </cftry>
    10.  
     
    cfStarlight, Nov 17, 2007 IP
  5. unitedlocalbands

    unitedlocalbands Peon

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you so much, I couldnt find the type of exception to use. Pointing out the stack trace I think Is going open many doors to me.

    Its working better then I could have imagined.

    I just realized I dont even need to have a cferror tag in the application.cfm file.


    I really apreciate all your help!:)

    Also I havent been able to get the error tag to send me an email

    Heres what I have been using but I cant figure out where to place it.



    Code (Text):
    1.  
    2. <cfoutput>
    3. <cfmail to="#error.MailTo#" from="my email" subject="Error On United Local Bands">
    4. There was an error:
    5.  
    6. #error.DateTime#
    7.  
    8. #error.Browser#
    9.  
    10. #error.HTTPReferer#
    11.  
    12. #error.Diagnostics#
    13. </cfmail>
    14. </cfoutput>
    15.  
    In some places it doesnt work and in others I get an error message

    Code (Text):
    1.  
    2. You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.  
    3.  
    4.  
     
    unitedlocalbands, Nov 18, 2007 IP
  6. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So you're using <cferror> to handle other exceptions (not the upload file exception, right?). Just so we're on the same page .. if you use cftry/cfcatch to handle a file exception it won't bubble up to your error handler unless you rethrow the error. Does that make sense? Not that you would want to be emailed every time someone tried to upload the wrong file type anyway ;)


    The cfmail code would go inside your error handler page. Keep in mind you can only use CF tags for type "exception", not "validation" or "request".

    Code (Text):
    1.  
    2. <!--- application.cfm --->
    3. <cfapplication name="Test" sessionmanagement="true" ... >
    4.   <cferror type="exception"
    5.     mailto="yourself@yoursite.net"
    6.     template="error_exception.cfm" >
    7.  
    8.  
    9. <!--- error_exception.cfm --->
    10.  
    11. <!--- display some message for user --->
    12. <cfoutput>
    13.     <b>Sorry an error occurred</b><br>
    14.     error.DateTime = #error.DateTime#<br>
    15.     error.Browser = #error.Browser#<br>
    16.     error.HTTPReferer = #error.HTTPReferer#<br>
    17.     error.Diagnostics = #error.Diagnostics#<br>
    18. </cfoutput>
    19.  
    20. <!--- send the email silently --->
    21. <cfmail to="#error.MailTo#" from="your email" subject="Error On United Local Bands" >
    22.     There was an error:
    23.     #error.DateTime#
    24.     #error.Browser#
    25.     #error.HTTPReferer#
    26.     #error.Diagnostics#
    27. </cfmail>
    28.  
     
    cfStarlight, Nov 18, 2007 IP
  7. unitedlocalbands

    unitedlocalbands Peon

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You got it, thats exactly what I would like to do.

    the cftry and cfcatch are for the file upload and your right I dont need to be emailed everytime they try to upload the wrong file. :)

    I have the Coldfusion MX7 book by Raymond Camden, but it's hard to read and understand at times. So I was a little confused about the different error types and how to address each of them.

    But you have worked them out.

    So I'm using the cftry and cfcatch for take care of the file upload.

    Now for the rest of the "unexpected" errors I will use the code you have provieded above.

    Thanks a bunch!
     
    unitedlocalbands, Nov 18, 2007 IP
  8. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yes, it can be confusing.

    Plus with MX7 introducing the Application.cfc, you can handle errors in the OnError function instead of using the <cferror> tag. (Is your head spinning yet.. ? ;)

    You can define different handlers for each exception type if you wanted. ie Display one page for database errors, another page for expression errors, ..etc. Unfortunately, it doesn't seem to work the way its supposed to with custom exceptions. I think its a bug.

    Then again, a single error handler for all exception types is often good enough. Custom exceptions can be over-kill for some applications.

    In case you're curious, here's an example of how you could show one page for db errors and another for expression errors

    Code (Text):
    1.  
    2. <!--- application.cfm --->
    3. <cfapplication name="Test" sessionmanagement="true">
    4. <cferror type="exception"
    5.     mailto="yourself@yoursite.net"
    6.     exception="database"
    7.     template="database_handler.cfm" >
    8. <cferror type="exception"
    9.     mailto="yourself@yoursite.net"
    10.     exception="expression"
    11.     template="expression_handler.cfm" >
    12.  
    13.  
    14. <!--- database_handler.cfm --->
    15. <h2>database_handler.cfm</h2>
    16. <cfdump var="#error#">
    17.  
    18. <!--- expression_handler.cfm --->
    19. <h2>expression_handler.cfm</h2>
    20. <cfdump var="#error#">
    21.  
    22. <!---
    23.     test_page.cfm (uncomment the code to test it)
    24. --->
    25.  
    26. <!--- this will cause an "expression" exception
    27. <cfset b = "this is a string">
    28. <cfset a = b * 1>
    29. --->
    30.  
    31. <!--- this will cause a "database" exception
    32. <cfquery name="q" datasource="ThisDoesntExists">
    33.     SELECT * FROM Nothing
    34. </cfquery>
    35. --->
    36.  
    37.  
     
    cfStarlight, Nov 18, 2007 IP