Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Using DBD::ODBC and cygwin to connect to MS SQL?

by Tommy (Chaplain)
on Jul 14, 2016 at 12:45 UTC ( #1167772=note: print w/replies, xml ) Need Help??


in reply to Re: Using DBD::ODBC and cygwin to connect to MS SQL?
in thread Using DBD::ODBC and cygwin to connect to MS SQL?

Oh, awesome! This looks promising, because I've been able to get the tsql command to work OK. It's just the odbcinst.ini file that's been a problem. I'm going to give this a shot in a few minutes and I'll let you know how it works out!

Tommy
A mistake can be valuable or costly, depending on how faithfully you pursue correction
  • Comment on Re^2: Using DBD::ODBC and cygwin to connect to MS SQL?

Replies are listed 'Best First'.
Re^3: Using DBD::ODBC and cygwin to connect to MS SQL?
by Tommy (Chaplain) on Jul 14, 2016 at 13:53 UTC

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1167772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2022-12-08 22:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?