title: How can I handle non-ASCII characters when retrieving data from SQL Server using Perl?
body: <p>I have a Perl script running on UNIX that uses DBI to connect to and retrieve data from a SQL Server database. The script looks like the following:</p>
  
  <pre><code>$dbh = DBI-&gt;connect("dbi:Sybase:server=$connect;charset=UTF-8", $login, $password) or die("Couldn't connect to $connect as $login/$password:
  $DBI::errstr");
  
  
  $sql = "use mydb";
  $sth = $dbh-&gt;prepare($sql);
  $sth-&gt;execute or die("execute failed");
  $sth-&gt;finish;
  
  
  $sql = "MyProc \@DATE='1/1/2008'";
  $sth = $dbh-&gt;prepare($sql);
  $sth-&gt;execute or die("execute failed");
  while (($body) = $sth-&gt;fetchrow()) {
          print "$body\n";
  }
  $sth-&gt;finish;
  
  $dbh-&gt;disconnect if $dbh;
  </code></pre>
  
  <p>The body variable retrieves data from a column that is NVARCHAR and contains non-ASCII characters.  The query runs fine, but the print statement spits out ????? when it encounters a non-ASCII character.  In DBI->connect I even specify the character set, but no luck.</p>
  
  <p>Any thoughts on how I can get this to work?</p>