I do this all the time. I couldn't get DBD::Sybase to fly for me, so I use DBD::ODBC.

First, you need to get unixODBC (either from your distro's packages or from here) (I've heard that iODBC also works but I haven't tried it).

You also need FreeTDS (your distro might not package this one). When building it, you'll want to pass "--with-unixodbc" to the configure script. You might also want to pass "--with-tdsver=7.0" if you've got MSSQL 7, or "--with-tdsver=8.0" if you've got SQL 2000 (haven't tried it with 2005 but I assume it'll work with 8.0). Build and install FreeTDS, and then you can set up your configs.

Assuming you passed "--prefix=/usr/local --sysconfdir=/etc" to your configure scripts, your configs should look something like this. Adjust paths to taste.

/etc/freetds.conf

[global] # skip misc freetds settings... [myserver] host = sql.example.com port = 1433 tds version = 8.0 # do tds version = 7.0 if SQL 7

/etc/odbcinst.ini

[FreeTDS] Description = FreeTDS MS SQL Server Driver Driver = /usr/local/lib/libtdsodbc.so Setup = /usr/local/lib/libtdsS.so

/etc/odbc.ini

[mydb] Description = My Example Database Driver = FreeTDS Servername = myserver # Servername should be the name of the section in freetds.conf Databse = mydb

Then install DBD::ODBC from CPAN, and connect with DBI->connect('dbi:ODBC:mydb', $username, $password)


In reply to Re: Connecting to MS SQL Server from linux by coldguy
in thread Connecting to MS SQL Server from linux by Anonymous Monk

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.