CFC 中带有查询的通信故障链接
我有一个 CFC,可以在招聘网站上处理“联系我们”类型的表格。 cfc 旨在处理站点中的几种不同形式;通用的“联系我们”表格和另一个“我对这份工作感兴趣”表格。
当 CFC 获取数据并且参数中包含职位发布的 ID 号时,CFC 会进行快速查询并获取职位发布信息,将其包含在电子邮件中并向 HR 部门和用户发送一封电子邮件,其中包含职位发布信息以及用户的联系信息。
如果未检测到 ID,CFC 只会向用户发送一封确认电子邮件,并将联系信息发送给人力资源部门。
当处理通用(非 ID)表单时,一切正常。但是,当需要处理包含快速查询的表单时,我收到一个错误:
通信链接故障 最后一个从服务器成功接收到的数据包是在 61,380 毫秒前。成功发送到服务器的最后一个数据包是在 0 毫秒前。
为什么填充我的页面的查询工作正常,但此 CFC 会抛出一个查询错误?
我们在共享托管环境上运行带有 MYSQL 的 CF9。
中资委...
<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="[email protected]" from="[email protected]" 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="[email protected]" from="[email protected]" 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="[email protected]" from="[email protected]" 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>
</cftry>
<cfelse>
<!-- regular ol form process goes here -->
</cfif>
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="[email protected]" from="[email protected]" 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="[email protected]" from="[email protected]" 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="[email protected]" from="[email protected]" 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>
</cftry>
<cfelse>
<!-- regular ol form process goes here -->
</cfif>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这不是您的代码的问题,而是您的托管公司应该调查的问题。
可能发生的情况是 ColdFusion 试图重用其连接池中的数据库连接,但通信链路已损坏。您通常可以通过向数据源设置添加验证查询(例如 SELECT 1)或禁用连接池来解决此问题。
我必须感谢 Steven Erat 在这个特定问题上的知识:http://forums.adobe.com /消息/3396333#3396333
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