Skip to main content
Known Participant
August 2, 2012
Question

Could not find prepared statement with handle 1.

  • August 2, 2012
  • 3 replies
  • 9280 views

[Macromedia][SQLServer JDBC Driver][SQLServer]Could not find prepared statement with handle 1.

I'm getting this error message in what appear to be random ways. The first time I look at a page I might not get it, but the second time I might. I discovered that removing a cfqueryparam tag worked, but that is not really a safe solution. I checked that the cf_sql_type matched the database field, and in one case changed a cf_sql_varchar to a cf_sql_char so it would match a SQL Server nchar(10) field. But still these errors. Any ideas? I've not had any luck Googling this.

I should add that I'm running Coldfusion 9 as a Tomcat webapp on a Linux server. The database is SQL Server 2005, I think.

This topic has been closed for replies.

3 replies

New Participant
June 29, 2015

I know this is a very old post but maybe this will help someone still experiencing this. I too was having the same issue and as a previous post suggested, it is related to the driver. I am going to assume that the OP is using the built in Microsoft SQL Server driver for the data source. Switching to the more perfomant jTDS driver eliminated these random errors.

P.S. We've since upgraded to CF11 and the issue still persists when using the SQL Server driver.

New Participant
September 14, 2012

Just to let you know that you are not crazy, I have had the same issue in CF9 (standard Windows install) with SQL Server 2005.  I also have not found a solution, and in all cases I have had to remove the <cfqueryparam> tag.  Restarting CF (or, alternately, restarting SQL Server) solves the problem temporarily, but after a few days it always comes back.

If you come across a solution, please update this post!

October 8, 2012

I had the same problem due to a query that errored then all subsequent queries would error as well with this error message

I found this blog post regarding this issue:

http://www.sstwebworks.com/entry.cfm?entry_id=AAF6E42A-F14A-4716-88B98BD231596CA6

Inspiring
August 2, 2012

hard to say without looking at your code.  However, since you mentioned cfqueryparam, maybe you are sending an empty string without specifying null="true" or something like that.

dcoliAuthor
Known Participant
August 2, 2012

It's possible there's something in my logic that is doing that ... but it was happening to one query that was referring to a value set at the top of the file (via cfqueryparam) and when I removed that cfqueryparam it started to happen to a different query. And, I should add, the queries in question were working fine for years before on a coldfusion MX server. This is a new page in the app, but the queries are all being included from old working template files.

dcoliAuthor
Known Participant
August 2, 2012

Here's the one that is breaking now:

<cfquery name="CheckCredentials" datasource="#application.crossreg_dsn#">

                                        SELECT [name_first]+' '+[name_last] as name

                                                    ,p.[uni]

                                                    ,p.email

                                                    ,p.role_id

                                                     ,r.role_name

                                                  ,p.external_program_id

                                          FROM [CrossReg].[dbo].[People] p

                                           INNER JOIN dbo.Roles r on r.role_id = p.role_id

                                          WHERE uni = <cfqueryparam cfsqltype="cf_sql_char" value="#Session.username#">

</cfquery>

Session.username is being returned from a CAS authentication system. I've never had troubles with it before.