Maximum list values for cfqueryparam
October 22, 2008
I've just managed to get ColdFusion 8 to blow up MS SQL Server 2000! This is the error message I was getting:
| Type | Database |
|---|---|
| Detail | [Macromedia][SQLServer JDBC Driver]The DBMS returned an unspecified error. The command code was 0. |
| Message | Error Executing Database Query. |
It turns out that this is due to passing a list with too many values to a cfqueryparam tag with the list attribute set to true. There are three simple solutions:
- As I know that the values are safe I'm not too worried about the security implications, so I could replace
IN ( <cfqueryparam value="#my_long_list#" cfsqltype="cf_sql_integer" list="true" /> )
with
IN ( #my_long_list# ). - Limit the number of values in the list I'm passing in.
- Use a subquery in my where clause.
In the interest of science I discovered that the maximum number of values that you can pass is 2096, which is a bit extreme and way more than is sensible!
- Posted in:
- SQL
- ColdFusion
7 comments
Leave a comment
If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)





if i could find who wrote the code i think i would slap them in their face haha.
The error I got was :-
org.apache.ojb.broker.PersistenceBrokerSQLException:
* Can't prepare statement: < lots and lots of sql here >
* Exception message is [Prepared or callable statement has more than 2000 parameter markers.]
* Vendor error code [0]
* SQL state code [22025]
I'm posting it in case it helps other people find this page when searching on google trying to figure out why their giant queries are killing sql server :)
Comment by Ciqala Burt – October 22, 2008
Comment by John Whish – October 22, 2008
Comment by Ciqala Burt – October 22, 2008
Comment by ike – October 22, 2008
Comment by Brian Kotek – October 22, 2008
@Ike, yeah that would do it, I guess you'd just have to not bind parameters in that instance. Although ticking 2096+ tick boxes would be a bit excessive :)
@Brian, I was using an 'IN' clause. I didn't know that about using EXISTS. Thanks for the tip.
Comment by John Whish – October 23, 2008
Comment by ike – October 23, 2008