Web Trenches

UTF-8 and Other Character Sets with ColdFusion

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.

4 Replies to “UTF-8 and Other Character Sets with ColdFusion”

  1. Monique, did you also confirm that in the ColdFusion Administrator you have ‘Enable High ASCII characters and Unicode for data sources configured for non-Latin characters’ checked for the data source you are using?

  2. Yes. that is checked. Weird this is that everything works on my local version of CF but not on the DEV server. Both datasources have the “Enable High ASCII characters…” option checked. Could there be some other server settings that are preventing it?

  3. In the SQL statement that is adding the text, is it using N’YOURVALUEHERE’?

    for example;

    insert into yourtable (yourcolumn)

Leave a Reply

Your email address will not be published. Required fields are marked *