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
    
    Error Executing Database Query.  
    [Macromedia][SQLServer JDBC Driver]Connection reset by peer: socket write error  
    
    Code (markup):
    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 Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #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.

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

    here is the cferror tag

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

    
    <cfoutput>
    <cfif isdefined("form.upload_now")>
    
    <CFIF IsDefined("Form.ul_path")>
    	<CFSET ul_path = "#Form.ul_path#">
    <CFELSE>	
    	<CFSET ul_path = "">
    </CFIF>
    
    <CFSET Valid = true>
    <CFSET Error = "">
    
    <cfif len(#form.ul_path#) LTE 0> 
    <CFSET Error = Error & "Please select an mp3.<BR>">
    <CFSET Valid = False>
    
    </cfif>
    
    
    
    <CFIF not Valid>
    		<STRONG>Sorry, An error occurred</STRONG>
    		<HR>
    		<CFOUTPUT><font size="+1" color="660000">#Error#</font></CFOUTPUT>
    		<EM>Please correct the error/errors</EM><br>
    		<A HREF="javascript:history.go(-1)"><br>Click Here To Return</A>
    
    </p>
    		    			   
    			   
    		       </div>
    		       <!-- End contenthome -->
    			   
    			   <div id="rightcolumnhome"></div>
    			   
             </div>	   
             <!-- End Faux Columns --> 
    
             <!-- Begin Footer -->
             <div id="footer">
    		       
                   <cfmodule template="sitefooter.cfm">
             </div>
    		 <!-- End Footer -->
    		 
       </div>
       <!-- End Wrapper -->
    </body>
    </html>		
    		
    		<cfabort>
    <CFELSE>
    
    <cfset uploadPath = GetDirectoryFromPath(GetTemplatePath()) & "#HELLO.USER_LOGINID##HELLO.USERID#\">
      <cfif not DirectoryExists(uploadPath)>
        <cfdirectory action="create" directory="#uploadPath#">
      </cfif>
    
    
    <cffile accept="audio/mpeg, audio/x-mpeg" action="upload" 
    destination="#uploadPath#" filefield="ul_path"  nameconflict="makeunique">
    
    
    <strong>YOUR SONG WAS UPLOADED SUCCESSFULLY!
    <cfset fileuploadpath = GetFileFromPath(cffile.ServerFile)> 
    <a href="savepath.cfm?uploadpath=<cfoutput>#HELLO.USER_LOGINID##HELLO.USERID#</cfoutput>\<cfoutput>#fileuploadPath#</cfoutput>">
    <font size="+2" color="##FFFF33">CLICK HERE TO FINNISH</font></a></strong>
    
    </CFIF>
    </cfif>
    </CFoutput>
    
    Code (markup):
    If they did select a file from the computer and filled in the form field then it will pass the file to this tag

    
    <cffile accept="audio/mpeg, audio/x-mpeg" action="upload" 
    destination="#uploadPath#" filefield="ul_path"  nameconflict="makeunique">
    
    Code (markup):
    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

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

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

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #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.



    
    <cfoutput>
    <cfmail to="#error.MailTo#" from="my email" subject="Error On United Local Bands">
    There was an error:
    
    #error.DateTime#
    
    #error.Browser#
    
    #error.HTTPReferer#
    
    #error.Diagnostics#
    </cfmail>
    </cfoutput>
    
    Code (markup):
    In some places it doesnt work and in others I get an error message

    
    You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.  
     
    
    Code (markup):
     
    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".

    
    <!--- application.cfm --->
    <cfapplication name="Test" sessionmanagement="true" ... >
      <cferror type="exception" 
    	mailto="yourself@yoursite.net" 
    	template="error_exception.cfm" >
    
    
    <!--- error_exception.cfm --->
    
    <!--- display some message for user --->
    <cfoutput>
    	<b>Sorry an error occurred</b><br>
    	error.DateTime = #error.DateTime#<br>
    	error.Browser = #error.Browser#<br>
    	error.HTTPReferer = #error.HTTPReferer#<br>
    	error.Diagnostics = #error.Diagnostics#<br>
    </cfoutput>
    
    <!--- send the email silently --->
    <cfmail to="#error.MailTo#" from="your email" subject="Error On United Local Bands" >
    	There was an error:
    	#error.DateTime#
    	#error.Browser#
    	#error.HTTPReferer#
    	#error.Diagnostics#
    </cfmail>
    
    Code (markup):
     
    cfStarlight, Nov 18, 2007 IP
  7. unitedlocalbands

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #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

    
    <!--- application.cfm --->
    <cfapplication name="Test" sessionmanagement="true">
    <cferror type="exception" 
    	mailto="yourself@yoursite.net"
    	exception="database" 
    	template="database_handler.cfm" >
    <cferror type="exception" 
    	mailto="yourself@yoursite.net" 
    	exception="expression" 
    	template="expression_handler.cfm" >	
    
    
    <!--- database_handler.cfm --->
    <h2>database_handler.cfm</h2>
    <cfdump var="#error#">
    
    <!--- expression_handler.cfm --->
    <h2>expression_handler.cfm</h2>
    <cfdump var="#error#">
    
    <!---
        test_page.cfm (uncomment the code to test it)
    --->
    
    <!--- this will cause an "expression" exception
    <cfset b = "this is a string">
    <cfset a = b * 1>
    --->
    
    <!--- this will cause a "database" exception 
    <cfquery name="q" datasource="ThisDoesntExists">
    	SELECT * FROM Nothing
    </cfquery>
    --->
    
    
    Code (markup):
     
    cfStarlight, Nov 18, 2007 IP