Recently I have had some difficulties with ColdFusion getting the ODBC Error Code = S1001 (Memory allocation error) error. I have read many articles trying find solutions to this problem but nothing that actually solved the problem. I have made sure of locking all my application and session variables as well as fine-tuned my queries to pass as little information as possible to and from the database server. I must admit that some progress has been made but under heavy traffic, eventually ColdFusion returns the S1001 memory allocation error. At this point I?m pretty much screwed. I do not have access to the ColdFusion service running on the web server and must rely on the IT staff to restart the service. As you might know, waiting on someone else to restart the service can seem like an eternity while you helplessly watch your website come to a screeching halt. This can be even more frustrating when it is the weekend and no one can be found to restart the service. As my site generates more traffic, it become even more imperative to ensure that ColdFusion is up and running. 

I thought, if I could just get access to the services running on the server? but then it occurred to me that while I don?t have security privileges to start and stop services, ColdFusion does! Why such a simple fact evaded me for so long I do not know why, but I have finally been able to write some code that will cause ColdFusion to restart itself and has been a life saver for me.

When ColdFusion gets the S1001 Memory Allocation Error (or any error that demands the service to restart) I execute the following code in my error.cfm (called by the <cferror> tag )?

	<cfif findnocase("ODBC Error Code = S1001", error.diagnostics)>
    	<cfset outfile="d:\mydir\ss.txt" />
  		<cfset cmd="d:\mydir\ss.bat" />
  		<cfset args="" />
  		<cfexecute name="#cmd#"
        	arguments="#args#"
            outputfile="#outfile#">
         </cfexecute>
	</cfif>

The contents of the ss.bat:

  @Echo off
  date /t
  time /t
  net stop "Cold Fusion Application Server"
  net start "Cold Fusion Application Server"
  exit

Contents of ss.txt after execution:

  Fri 06/13/2003 
  12:23p
  The Cold Fusion Application Server service is stopping.
  The Cold Fusion Application Server service was stopped successfully.

  The Cold Fusion Application Server service is starting.
  The Cold Fusion Application Server service was started successfully.

<cfexecute> executes the contents of the ss.bat batch file which directs the ColdFusion service to stop and then start. Once this code is executed the service is up and running again. I do not have to worry about the service sitting in limbo any longer. Of course someone has to get the error in order for the <cferror> to execute. However with careful planning and using the <cftry><cfcatch> you will be able to catch this error and immediately act upon it restarting ColdFusion automatically when needed.

About This Tutorial
Author: Anthony Moore
Skill Level: Intermediate 
 
 
 
Platforms Tested: CF5
Total Views: 89,508
Submission Date: June 13, 2003
Last Update Date: August 25, 2011
All Tutorials By This Autor: 1
Discuss This Tutorial
Advertisement

Sponsored By...
Mobile App Development (IOS, Android, Cordova, Phonegap, Objective-C, Java) - Austin, Texas Mobile Apps - Touch512, LLC.