Hi all, I have a perl script running from a linux server, connecting to a SQL server 2008 and retrieving data. when ever the data is hebrew i get question marks only. I tried using decode, encode, with no success.
Your help please.
Also, when using a PHP script all works well.

The SQL INFORMATION_SCHEMA:
DATA_TYPE: nvarchar.
CHARACTER_SET_NAME: UNICODE.
COLLATION_NAME: Hebrew_CI_AI.

The code:
#!/usr/local/bin/perl -w use CGI; use DBI(); use warnings; use utf8; $q = CGI->new; $q->header(-encoding => 'UTF-8', -charset => 'UTF-8', -expires => '-1d +'); print "Content-Type: text/html; charset=UTF-8"; print $q->header; print $q->start_html(-title => 'Test Heb'); $sql = <<EOSQL; select Opportunity.AccountIdName from Opportunity; EOSQL $data_source = q/dbi:ODBC:SQLSRV/; $user = q/xxx/; $password = q/xxx/; $dbh = DBI->connect($data_source, $user, $password) or &errSub("Problem.\nCan't connect to SQL.",__LINE__,1); $dbh->{'LongReadLen'} = 25000; $dbh->{'LongTruncOk'} = 1; $dbh->do(q/SET names 'utf8'/); $sth = $dbh->prepare($sql); $sth->execute() or &errSub("Problem.\nCan't excute SQL query [$DBI::er +rstr].\nFailed search.",__LINE__,1); $rows = $sth->rows; if ($rows) { print "<pre>\n"; while ($ref = $sth->fetchrow_hashref()) { $AccountIdName = ($ref->{'AccountIdName'} || 'Null'); print "$AccountIdName\n"; } $sth->finish(); } else { $sth->finish(); next; } $dbh->disconnect; exit 0;

In reply to perl odbc mssql encoding problem by ori smaug

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.