OK, here's what worked for me, in 5 steps:
Step 1: don't worry about /etc/odbc.ini -- you don't need to create or modify it to make your MS SQL connection work from cygwin.
Step 2: you also don't need to worry about /etc/freetds/freetds.conf -- the defaults work out of the box
Step 3: set up your /etc/odbcinist.ini file like so:
[FreeTDS]
Description = TDS Conection
Driver = /usr/lib/cygtdsodbc.dll
Setup = /usr/lib/cygtdsodbc.dll
UsageCount = 1
FileUsage = 1
Step 4: write your Perl code like so (change as desired) #TMTOWTDI
#!perl
use strict;
use warnings;
use 5.020;
use DBI;
my ( $user, $pass ) = ( 'username goes here', 'password goes here' );
my $dsn =
{
driver => 'FreeTDS',
server => 'my.server.host.name',
database => 'name_of_db_here',
port => 1433,
tds_ver => '8.0'
};
$dsn = sprintf 'dbi:ODBC:DRIVER={%s};SERVER=%s;database=%s;port=%s;tds
+_version=%s;',
$dsn->{driver},
$dsn->{server},
$dsn->{database},
$dsn->{port},
$dsn->{tds_ver};
my $dbi_opts =
{
PrintError => 0,
RaiseError => 1,
AutoCommit => 1,
LongReadLen => 24 * 1024,
LongTruncOk => 1,
odbc_utf8_on => 1,
};
my $dbh = DBI->connect ( $dsn, $user, $pass, $dbi_opts );
my $rows = $dbh->selectall_arrayref( 'SELECT * from some_table_you_kno
+w' );
use Data::Dumper;
say Dumper $_ for @$rows
Step 5: Profit!
It turns out that this wasn't nearly as complicated as I initially was led to believe, and that's fine by me :-)
Tommy
A mistake can be valuable or costly, depending on how faithfully you pursue correction
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.