Communications failure link in CFC with query
I have a CFC that processes a 'contact us' kind of form on a job posting site. The cfc is designed to handle a couple of different forms from the site; a generic 'contact us' form and another 'I'm interested in this job' form.
When the CFC gets the data, and an ID# for the job posting is in the arguments, the CFC does a quick query and grabs the job posting information, includes it in an email and sends the HR department and the user an email with the job posting info as well as the user's contact info.
If no ID is detected, the CFC just emails the user a confirmation email and sends the contact info to the HR department.
When the generic (non ID) form is processed all works well. But, when it comes time to process the form that includes the quick query I get an error:
Communications link failure The last packet successfully received from the server was 61,380 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
Why does the query that populates my page work fine but this CFC throws an error with a query in it?
We're running CF9 with MYSQL on a shared hosting environment.
The CFC...
<cfif len(local.data.job_id)>
<cftry>
<cfquery name="qJobsforEmail" datasource="#application.datasource#" username="#application.username#" password="#application.password#">
SELECT * FROM #local.data.table# WHERE #local.data.table#.#local.data.column#= <cfqueryparam value="#local.data.job_id#" cfsqltype="cf_sql_numeric">
</cfquery>
<cfcatch type="any">
<cfmail to="my@email.com" from="server@host.com" subject="Error processing query" type="html">
<h3>There was an error processing the query</h3>
<p><cfoutput>#cfcatch.Detail#</cfoutput></p>
<p><cfoutput>#cfcatch.NativeErrorCode#</cfoutput></p>
<p><cfoutput>#cfcatch.SQLState#</cfoutput></p>
<p><cfoutput>#cfcatch.Sql#</cfoutput></p>
<p><cfoutput>#cfcatch.queryError#</cfoutput></p>
<p><cfoutput>#cfcatch.where#</cfoutput></p>
<p><cfoutput>#cfcatch.type#</cfoutput></p>
<cfdump var="#local#">
</cfmail>
<cfset local.response["error"] = 'true'>
<cfset local.response["message"] = 'Error message to the page goes here...'>
<cfreturn local.response>
<cfabort>
</cfcatch>
</cftry>
<cftry>
<cfmail to="#local.data.email#" bcc="hr@theclient.com" from="server@host.com" subject="Thank you for contacting us" type="html">
<h2>We’re glad you contacted us.</h2>
<p>Warm and fuzzy thank you message here</p>
<p>We received the following information on <cfoutput>#DateFormat(Now())#</cfoutput>, <cfoutput>#TimeFormat(Now())#</cfoutput>: </p>
<p>First Name: <cfoutput>#local.data.first_name#</cfoutput></p>
<p>Last Name: <cfoutput>#local.data.last_name#</cfoutput></p>
<cfif len(local.data.suffix)>
<p>Suffix: <cfoutput>#local.data.suffix#</cfoutput></p>
</cfif>
<p>Specialty: <cfoutput>#local.data.specialty#</cfoutput></p>
<p>Email Address: <cfoutput>#local.data.email#</cfoutput></p>
<p>Phone: <cfoutput>#local.data.phone#</cfoutput></p>
<p> Current City and State: <cfoutput>#local.data.city#</cfoutput></p>
<cfif len(local.data.comments)>
<p>Message: <cfoutput>#local.data.comments#</cfoutput></p>
</cfif>
<p style="border-top:thin dotted black;padding-top:20px;font-weight:bold;">This is the position you’re inquiring about:</p>
<p style="font-weight:bold;"><cfoutput>#qJobsforEmail.title#</cfoutput></p>
<p style="padding-bottom:20px;"><cfoutput>#qJobsforEmail.description#</cfoutput></p>
<p>Our Recruiter will review this information and get in touch with you as soon as possible. Please make sure your email or phone number listed above is correct.</p>
<p>Thanks again for contacting us. We look forward to speaking with you soon.</p>
</cfmail>
<cfcatch type="any">
<cfmail to="my@email.com" from="server@host.com" subject="Error processing email" type="html">
<h3>There was an error processing the email at</h3>
<cfdump var="#cfcatch.Detail#">
<cfdump var="#local#">
</cfmail>
<cfset local.response["error"] = 'true'>
<cfset local.response["message"] = 'message to return to the page...'>
<cfreturn local.response>
<cfabort>
</cfcatch>
开发者_JAVA技巧</cftry>
<cfelse>
<!-- regular ol form process goes here -->
</cfif>
I don't think it's a problem with your code but rather one that your hosting company should be looking into.
What is probably happening is ColdFusion is trying to reuse a database connection from its connection pool, but the communication link is broken. You can usually remedy this by adding a validation query to the datasource settings (eg SELECT 1) or by disabling connection pooling.
I have to credit Steven Erat for his knowledge on this particular issue: http://forums.adobe.com/message/3396333#3396333
精彩评论