To explain this a bit, you need two things outside of Perl, FreeTDS, and iODBC/UnixODBC. I use UnixODBC, so setup for iODBC may vary slightly.

FreeTDS is the driver you'll use to actually handle the connection to the database via ODBC. Given that, you have to tell UnixODBC how to use the installed FreeTDS driver.

· Once FreeTDS is installed, make sure it is installed to work with UnixODBC via tsql -C
· Find the location of your odbcinst.ini by running odbcinst -s -j
· Edit your odbcinst.ini file to add the FreeTDS driver as below:

# Driver from the FreeTDS package # Setup from the unixODBC package [FreeTDS] Description = ODBC for FreeTDS Driver = /usr/lib/cygtdsodbc.dll Setup = /usr/lib/cygtdsodbc.dll FileUsage = 1

Then, your connection string will be as follows in Perl:

my $dsn = 'dbi:ODBC:DRIVER={FreeTDS};'; $dsn .= 'SERVER=DB.EXAMPLE.COM;database=NorthWind;'; $dsn .= 'port=1433;tds_version=8.0;'; my $dbh = DBI->connect($dsn, 'username', 'password', { PrintError => 0, # don't automatically print out error messages RaiseError => 1, # die on error AutoCommit => 1, # automatically committed when executed LongReadLen => 24*1024, # SQL Server limit LongTruncOk => 1, # don't die when we grab really long data :/ odbc_utf8_on => 1, # utf8 all data. We'll need to decode everything });

Once you get things working, please line out the steps for me and I will update the gist here: https://gist.github.com/genio/7c7fc52fcb8be5d486aa to reflect this environment's process.


In reply to Re: Using DBD::ODBC and cygwin to connect to MS SQL? by genio
in thread Using DBD::ODBC and cygwin to connect to MS SQL? by Tommy

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.