I am using DBI::ODBC to connect to MS SQL Server 2000 and I need to pull the SID for a given user out of the sysusers table. This column is varbinary though and is creating havoc on my output.

Here is some sample code:

my $DSN = 'driver={SQL Server};Server=new-borg;database=master;uid=;pw +d=;'; my $dbh = DBI->connect("dbi:ODBC:$DSN") or die "$DBI::errstr\n"; my $sql = qq{ select * from sysusers }; my $sth = $dbh->prepare ($sql); $sth->execute(); while (@row = $sth->fetchrow_array()) { print $#row,':',join(':',@row),"\n"; } $sth->finish();

Some output from this is here:

5:14:IUSRBEVO:☺♣ ♣§ ₧§J|╝zê∟ +j7╞? : :2000-09-22 14:08:48.217:2000-09-22 14:08:48.217:0::0:: +1:1:1:0:1:0:0:0:0 7:2:ARAdmin:♥┼ºoAá╥◄╜╜ á$J§╛ +:@:2003-02-18 13:08:06.370:2003-02-18 13:08:06.697:0::0::1:1:0:0:0:1: +0:0:0
But, when I query this in SQL Server I get the following:
5:14:IUSRBEVO:0x0105000000000005150000009E15AE084A7CBC7A881C6A37C63F00 +00:0x00:2000-09-22 14:08:48.217:2000-09-22 14:08:48.217:0:NULL:0:NULL +:1:1:1:0:1:0:0:0:0 7:2:ARAdmin:0x03C5A76F41A0D211BDBD00A0244A15BE:0x40:2003-02-18 13:08:0 +6.370:2003-02-18 13:08:06.697:0:NULL:0:NULL:1:1:0:0:0:1:0:0:0

Notice that the 4th column in SQL Server starts with "0x" and then the SID but the text I get does not as it is being interpreted as a binary number.

Anyone have experience with this? Getting text out of a varbinary column?

Ed


In reply to SQLServer varbinary headache by bfdi533

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.