Sign Doug's SOTR Petition!

Sign Doug's petition to his boss and help send him to Scotch on the Rocks in 2012!
Recent Entries
Contact Doug!
Learn About Doug!
View Doug Boude's online resume
updated 11/18/2009

View Doug Boude's profile on LinkedIn
Link to me!

Follow Doug Boude on Twitter
Follow me!

Be Doug's friend on Facebook
Befriend me!
(I promise not to follow you home)
OO Lexicon
Chat with Doug!
NO MORE CAREER
POLITICIANS!
Get Out Of Our House: Replacing congress with TRUE citizens!
You may also be interested in...
Web Hosting
best web hosting - top web hosting sites, thetop10bestwebhosting.com

Czech your Page Rank!
Check Page Rank of any web site pages instantly:
This free page rank checking tool is powered by Page Rank Checker service
Surf's Up!
Visit Egosurf.org and massage YOUR web ego!
My Score: 9,001
Doug's Books

Read (and recommend)

  • Men are from Mars, Women are from Venus
  • The Wisdom of Crowds: Why the Many Are Smarter Than the Few and How Collective Wisdom Shapes Business, Economies, Societies and Nations
  • Blink: The Power of Thinking Without Thinking
  • Head First Design Patterns
  • Transact-SQL Programming
  • What's So Amazing About Grace?
  • Just So Stories (Rudyard Kipling collection)

Reading

  • Prayer: Does it Make Any Difference?
  • Data Mining (Practical Machine Learning Tools and Techniques)
<< February, 2012 >>
SMTWTFS
1234
567891011
12131415161718
19202122232425
26272829
Search Blog

Recent Comments
Re: Why I Hate ORMs (a solicited rant) (by aris setyawan at 2/20 2:48 AM)
Re: Element.show/hide anomoly in Prototype (by Jens at 2/19 6:30 AM)
Re: My Twelve Steps to a Coldbox App (by Francesco at 2/17 12:06 AM)
Re: SQL Forward Engineering with Visio 2003 Professional (by Leo at 2/13 10:55 AM)
Re: Basic Ajax Select List Filter in PHP (by opineemia at 2/02 8:47 PM)
Re: PHP vs COLDFUSION (by dougboude at 1/24 9:47 AM)
Re: PHP vs COLDFUSION (by WhatTheHeck at 1/23 7:03 PM)
Re: Recursive Functions in ColdFusion (by Marty McGee at 1/22 1:01 PM)
Re: SQL Forward Engineering with Visio 2003 Professional (by Rama at 1/10 11:05 AM)
Re: PHP Export to Excel Snippet (by rasha at 1/10 1:55 AM)
Re: Fredrick "French" Fry (by Picky eater at 1/09 2:21 PM)
Re: Disappearing IE Popup Window During Save/Open Dialog (by Vivekanand at 1/06 12:51 AM)
Re: Just What IS a 'Service Layer', Anyway? (by Ashishkumar Haldar at 1/05 7:49 AM)
Re: Viewing Option Text (in IE7) that's Wider than the Select List (by ranjit sachin at 12/20 6:22 AM)
Re: Recursive Functions in ColdFusion (by Jason at 12/15 12:13 PM)
Re: Viewing Option Text (in IE7) that's Wider than the Select List (by kt at 12/08 3:47 AM)
Re: PayPal IPN Coldfusion CFC (by Guest at 11/28 6:11 PM)
Re: SQL Forward Engineering with Visio 2003 Professional (by freddy villamil at 11/09 2:49 PM)
Re: Finally Found a Use for CFTHREAD (by criclebrava at 11/09 1:23 PM)
Re: Finally Found a Use for CFTHREAD (by assisisowsfub at 11/07 10:37 PM)
Categories
Archives
Photo Albums
Funnies (5)
Family (3)
RSS

Powered by
BlogCFM v1.11

07 October 2011
IRRITATING CF QUERY ERROR AND SOLUTION
Incorrect string value: '\xC2....'

Today I'd like to help save someone from pulling their hair out when they encounter a Coldfusion error similar to the following:

Error Executing Database Query. Incorrect string value: '\xC2\x96 OTH...' for column 'Comments' at row 1

This error would occur during a database insert or update, and very likely when trying to execute a query that does NOT use the CFQUERYPARAM tags.

TANGENT BEGIN

I'll just indulge the tangent for a moment since I mentioned doing something that ought not to be done and toss in at least one occasion when it is acceptable NOT to use them. When building a dynamic sql statement that you then want to execute, you cannot include cfqueryparam tags and have it work; CF will barf on it. Here's a rough example of what I'm talking about:

<cfset thisSQL = "INSERT INTO MYTABLE ('field1','field2',field3') VALUES (" />
<cfset thisSQL = "#thisSQL# '#val1#','#val2#','#val3#')" />
<cfquery name="qryInsert" datasource="#dsn#">
 #preserveSingleQuotes(thisSQL)#
</cfquery>

In that scenario, you can't use CFQUERYPARAM.

TANGENT END

Okay, back to the point. So you've built this dynamic sql statement, values being gotten by parsing some incoming text file, let's say, and when you try to execute your statement you get the "Error Executing Database Query. Incorrect string value: '\xC2\x96 OTH...' for column 'Comments' at row 1" error. Thinking the statement is malformed, you paste it directly into your favorite query analyzer to try and execute it directly in the database and it works fine. You then feed the same incoming data file to your test server to see if the error is consistent, but it works FINE on your test server.

(skip a lot of hair pulling and frustration...)

THE SOLUTION

The problem turns out to be that the incoming file contains high ascii values, or characters outside of the "safe zone", and for whatever reason, your server barfs on it (even though your test server and the db itself doesn't). The solution then is to strip out all high ascii values before trying to use the string in your sql statement. Like so:

<cfset val1 = rereplace(val1,"[^\x00-\x7F]","","all") />

That'll get rid of that pesky irritating useless error, for ya! You're welcome. No charge.




Posted by dougboude at 12:29 PM | PRINT THIS POST! |Link | 2 comments
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: IRRITATING CF QUERY ERROR AND SOLUTION
The solution is to use cfqueryparam.

The code you've posted doesn't need to be done as a dynamic string, and even when people think they have got a situation which "must" be done that way, there's a way to do it as a normal query.

Using cfqueryparam works, and doesn't require screwing about with the data.
Posted by Peter Boughton on October 7, 2011 at 3:15 PM

Re: IRRITATING CF QUERY ERROR AND SOLUTION
Hey there Pete. The code I posted is off the cuff sample code illustrating the creation of a query string, not a direct snippet from the code I was working with. But, had that snippet of elementary code been actual code, then yeah, you would be 100% correct! And when possible, using cfqueryparam IS the answer. But I have to differ with your opinion that it is ALWAYS possible to use a normal query, because no, that is not necessarily the case. Perhaps you're working with legacy code where a rewrite isn't in the budget...there's a thought.
SO, when you DO have to build a query string, for WHATEVER reason, and encounter the error I described, my solution does address it.
Posted by dougboude on October 10, 2011 at 10:48 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Time to take the Turing Test!!!

Six plus Twelve equals
Type in the answer to the question you see above:

Your comment:

Sorry, no HTML allowed!