title: Convert UTF-8 String Classic ASP to SQL Database
body: <p>So I was having an issue with converting French characters correctly. Basically, I have a form which sends data to an SQL Database. Then, on another page, data from this DB is retrieved and displayed to the user. But the data (strings) were being displayed with wierd corrupt characters because the input in the form on the other page was in French. I overcame this problem by using the following function which converters a string to the correct charset. HOWEVER, obviously the better solution is to convert it FIRST and then send it to the database. Now here's the code to convert a string retrieved from a DB to the appropriate charset:</p>
  
  <pre><code>Function ConvertFromUTF8(sIn)
  
      Dim oIn: Set oIn = CreateObject("ADODB.Stream")
  
      oIn.Open
      oIn.CharSet = "WIndows-1252"
      oIn.WriteText sIn
      oIn.Position = 0
      oIn.CharSet = "UTF-8"
      ConvertFromUTF8 = oIn.ReadText
      oIn.Close
  
  End Function
  </code></pre>
  
  <p>I got this function from here: <a href="https://stackoverflow.com/questions/916118/classic-asp-how-to-convert-a-utf-8-string-to-ucs-2/920405#920405">Classic ASP - How to convert a UTF-8 string  to UCS-2?</a></p>
  
  <p>Now my question is, what function do I use to convert strings beforehand and then send them to the database, so that when I retrieve them they will be good-to-go?</p>
  
  <p><strong>Tried Paul's Method:</strong></p>
  
  <p>So there's page 1, and page 2. Page 1 contains a form which, when submitted, sends the string to the DB which is then retrieved in page 2. I tried Paul's solution by removing the function ConvertFromUTF8 and leaving it to as it was before (it returned wierd mangolian characters). After that, I added the following line on top of Page 1 as well as Page 2.</p>
  
  <pre><code>&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%&gt;
  </code></pre>
  
  <p>I also have the following on both of the pages:</p>
  
  <pre><code>Response.CodePage = 65001 
  Response.CharSet = "UTF-8" 
  </code></pre>
  
  <p>But it didn't work :(</p>
  
  <p><strong>Edit: it works!, thank you so much everyone for your help!
  All I needed to do was add "CodePage = 65001" on top of Page 3 (which I didn't even talk about), where the writing to the DB part was happening.</strong></p>