title: Read a CSV file with special characters in Ruby and store into SQL Server
body: <p>I'm trying to import a CSV file (UTF-8 encoding) in Ruby (2.0.0) in to my database (MSSQL 2008R2, <code>COLLATION French_CI_AS</code>), but the special characters (French accents on vowels) are not stored properly : <code>éèçôü</code> becomes <code>ÃƒÂ©ÃƒÂ¨ÃƒÂ§ÃƒÂ´ÃƒÂ¼</code> (or other similar jibberish).</p>
  
  <p>I use this piece of code to read the file :</p>
  
  <pre><code>CSV.foreach(file, col_sep: ';', encoding: "utf-8") do |row|
     # ...
  end
  </code></pre>
  
  <p>I tried various encoding in the CSV options (<code>utf-8</code>, <code>iso-8859-1</code>, <code>windows-1252</code>), but none would store the special characters correctly. </p>
  
  <p>Before you ask, my database collation supports those characters, since we have successfully imported data containing those using PHP importers. If I dump the data using <code>puts</code> or a file logger, everything is correct.</p>
  
  <p>Is something wrong with my code, or do I need to specify something else (like the ruby class file encoding for example) ?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT :</strong> The data saving is done by a PHP REST API that works fine with accented characters. It stores data as it is received. </p>
  
  <p>In Ruby, I parse my data, store it in an object and then send the JSON-encoded object in the body of my PUT request. But if I use an SQL query directly from Ruby, the problem remains :</p>
  
  <pre><code>query = &lt;&lt;-SQL
      UPDATE MyTable SET MyTable_title = '#{row_data['title']}' WHERE MyTable_id = '#{row_data['id']}'
  SQL
  res = db.execute query
  </code></pre>