UTF-8 and Other Character Sets with ColdFusion

ColdFusion , Default , Web Development Add comments

This has probably been written about many times before, but it stumped me today, so I thought I would share in case it saves anyone else some time.  By default, ColdFusion does not store data as UTF-8 into SQL Server.  This is a problem for Chinese characters sets, as well as many others.  I struggled with this for a while, and found partial answers in several articles online.  Here is the formula...

1. Set your data type to nvarchar in your database table.

2. In ColdFusion Administrator, in your datasource settings, click 'Show Advanced Settings', and be sure to check the box for 'Enable High ASCII characters and Unicode for data sources configured for non-Latin characters'.  

3. In your form processing script (where you are doing your CF database insert), include the following lines:
<cfprocessingDirective pageencoding="utf-8">
<cfset setEncoding("form","utf-8")>

Step 3 should not be necessary in the newer versions of ColdFusion, but it does not hurt anything to include it.

With these three steps completed, all of our form data that included extended characters started working.

0 responses to “UTF-8 and Other Character Sets with ColdFusion”

Leave a Reply

Leave this field empty:



Powered by Mango Blog. Design and Icons by N.Design Studio