in reply to Using DBD::ODBC and cygwin to connect to MS SQL?
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Using DBD::ODBC and cygwin to connect to MS SQL?
by Tommy (Chaplain) on Jul 14, 2016 at 12:45 UTC | |
by Tommy (Chaplain) on Jul 14, 2016 at 13:53 UTC |