Convert UTF-8 String Classic ASP to SQL Database

Paul’s answer isn’t wrong but it is not the only part to consider:

You will need to go through each of these steps to make sure that you are getting consistent results;

IMPORTANT: These steps have to be performed on each and every page in your web application or you will have problems (emphasized by Paul’s comment).

  1. Each page needs to be saved using UTF-8 encoding double check this as some IDEs will default to Windows-1252 (also often misnamed as “ANSI”).

  2. Each page will need the following line added as the very first line in the page, to make this easier I put this along with some other values in an include file so I can include them in each page as I go.

    Include File – page_encoding.asp
    <%@Language="VBScript" CodePage = 65001 %>
    <% 
      Response.CharSet = "UTF-8"
      Response.CodePage = 65001
    %>
    

    Usage in the top of an ASP page (prefer to put in a config folder at the root of the web)

    <!-- #include virtual="/config/page_encoding.asp" -->
    

    Response.Charset = "UTF-8" is the equivalent of setting the ;charset in the HTTP content-type header.
    Response.CodePage = 65001 tell’s ASP to process all dynamic strings as UTF-8.

  3. Include files in the page will also have to be saved using UTF-8 encoding (double check these also).

Follow these steps and your page will work, your problem at the moment is some pages are being interpreted as Windows-1252 while others are being treated as UTF-8 and you’re ending up with a mis-match in encoding.

Leave a Comment