How to use ODBC on AgensGraph? - agens-graph

Is there ODBC Driver on AgensGraph?

Officially, AgensGraph does not support ODBC Driver.
But, ODBC Driver for PostgreSQL is compatible partially.
You can download source code of ODBC Drivser on "http://odbc.postgresql.org".
After download source, Run procedures on follow.
$ tar xzf psqlodbc-*.tar.gz
$ cd psqlodbc-*
$ ./configure
$ make
$ sudo make install
After Driver installed, You must register AgensGraph on "odic.ini".
$ cat >$HOME/.odbc.ini <<EOF
[agensgraph]
Description = ODBC for AgensGraph
Server = localhost
Port = 5432
Database = $USER
Driver = /usr/local/lib/psqlodbcw.so
Setup = /usr/local/lib/libodbcpsqlS.so
Driver64 = /usr/local/lib/psqlodbcw.so
Setup64 = /usr/local/lib/libodbcpsqlS.so
FileUsage = 1
EOF
You can test ODBC connection using "isql" command.
$ isql agensgraph
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>

Related

Data source name not found and no default driver specified - Zabbix

I am trying to monitor an MSSQL database via ODBC with Zabbix, but I was getting an error that my DSN is invalid, even after performing several tests, does anyone have any idea what it could be?
/etc/freetds.conf
[MSSQL_SERVER]
host = <ip>
port = 1433
tds version = 8.0
/etc/odbcinst.ini
[FreeTDS]
Description= FreeTDS Driver for Linux & MSSQL
Setup= /usr/lib64/libtdsodbc.so.0
Driver = /usr/lib64/libtdsodbc.so.0
UsageCount=1
/etc/odbc.ini
[MSSQL]
Driver = FreeTDS
Servername = MSSQL_SERVER
isql DSN
[root#zabbix]# isql MSSQL sa <password>
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> quit
tsql Servername
[root#zabbix]# tsql -S MSSQL_SERVER -U sa -P <password>
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> quit
tsql conf
[root#zabbix]# tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v1.1.20
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: auto
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: no
GnuTLS: yes
MARS: yes
Error: Cannot connect to ODBC DSN: [SQL_ERROR]:[IM002][0][[unixODBC][Driver Manager]Data source name not found and no default driver specified]
Template:

BCP utility on linux: NativeError = 18456 Error = [unixODBC][Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user

Following BCP example (installed on CentOS7 via https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-2017#a-idrhelainstall-tools-on-rhel-7 with the msodbcsql driver from https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017) for importing flatfile from linux to a MSSQL Server (https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-migrate-bcp?view=sql-server-2017#import-data-from-the-source-data-file), getting error when trying to run basic command to write a flatfile from local machine (CentOS7) to a remote (Windows Server 2012) host DB.
The script being used for testing here looks like:
[me#mapr001 examples]$ cat simple-bcp-tsv2mssql.sh
#!/bin/bash
TO_SERVER_ODBCDS="-D -S 'ODBC Driver 17 for SQL Server'"
TO_SERVER_IP="-S 172.17.9.29"
DB="DB_ML"
TABLE="bcp_test"
USER=""
PASSWORD=""
DATAFILE="./data/simple-rows.headless.tsv"
read -r -p "Enter username: " USER
read -r -s -p "Enter user password: " PASSWORD
echo -e "\nConnecting with BCP utility as $USER..."
/opt/mssql-tools/bin/bcp "$TABLE" in "$DATAFILE" \
"$TO_SERVER_DNS" \
-U "$USER" \
-P "$PASSWORD" \
-d "$DB" \
-c \
-t "'\t'"
and is throwing the (seemingly misleading) error
[me#mapr001 examples]$ ./simple-bcp-tsv2mssql.sh
Enter username: me
Enter user password:
Connecting with BCP utility as me...
/opt/mssql-tools/bin/bcp: unknown option
usage: /opt/mssql-tools/bin/bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
...
even though I appear to be following this usage format in the script. The results when running via commandline are what I think I should really be focusing on:
[me#mapr001 examples]$ bcp bcp_test in ./data/simple-rows.headless.tsv -D -S MyMSSQLServer -U me -P mypassword -d DB_ML -c -t '\t'
SQLState = 28000, NativeError = 18456
Error = [unixODBC][Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'me'.
The /etc/odbc/odbc files on this machine look like
# Referencing some of the ODBC setup steps here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-RHEL-6-or-Centos-7
# Prepare a temp file for defining the DSN to your database server
vi /home/user/odbcadd.txt
[MyMSSQLServer]
Driver = ODBC Driver 17 for SQL Server
Description = My MS SQL Server
Trace = No
Server = 172.17.9.29
# register the SQL Server database DSN information in /etc/odbc.ini
sudo odbcinst -i -s -f /home/me/odbcadd.txt -l
[me#mapr001 examples]$ cat /etc/odbc.ini
[MyMSSQLServer]
Driver=ODBC Driver 17 for SQL Server ------------
Description=My MS SQL Server |
Trace=No |
Server=172.17.9.29 |
|
[MyMSSQLServer_ML] |
Driver=ODBC Driver 17 for SQL Server |
Description=My SQL Server (ML DB) |
Tracec=No |
Server=172.17.9.29 |
Database=DB_ML |
|
|
[me#mapr001 examples]$ cat /etc/odbcinst.ini |
[PostgreSQL] |
Description=ODBC for PostgreSQL |
Driver=/usr/lib/psqlodbcw.so |
Setup=/usr/lib/libodbcpsqlS.so |
Driver64=/usr/lib64/psqlodbcw.so |
Setup64=/usr/lib64/libodbcpsqlS.so |
FileUsage=1 |
|
[MySQL] |
Description=ODBC for MySQL |
Driver=/usr/lib/libmyodbc5.so |
Setup=/usr/lib/libodbcmyS.so |
Driver64=/usr/lib64/libmyodbc5.so |
Setup64=/usr/lib64/libodbcmyS.so |
FileUsage=1 |
|
[ODBC Driver 17 for SQL Server] <----------------
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1
UsageCount=1
[me#mapr001 ~]# odbcinst -q -d -n "ODBC Driver 17 for SQL Server"
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1
UsageCount=1
[me#mapr001 ~]# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /etc/odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
The problem appears to be related to how I've setup ODBC drivers and configs or with my credentials (which are Active Directory credentials that I use to login to the remote Windows machine hosting the SQL Server I'm trying to connect to here), but I have zero experience setting this kind of thing up and at this point am at a bit of a loss as to what to do (will continue researching and debugging). Any advice on how to further debug or fix the problem would be appreciated.
The problem appears to be that the bcp utility expects credentials for the SQL Server (see https://learn.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2017#U and https://learn.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2017#T), not the crednetials for the host machine that the SQL Server is running on.
In my original post, was using the domain Active Directory creds. that I would normally use to login to the machine (which, again, is wrong (further supported here: https://www.sqlservercentral.com/Forums/FindPost1565871.aspx)). Using a separate set of SQL Server credentials instead in the command solved my problem. (Still don't get why the script is throwing "unknown option" error, so if anyone has a guess, please leave a comment).
UPDATE: After some "binarysearch debugging" (https://www.codelord.net/2012/04/10/using-binary-search-for-debugging/), found that the problem was that the field_term option (https://learn.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-2017#t) was formatted in a way that was causing some problems. Originally wrote the code in the script as -t "'\t'". Changing this to -t "\t" (no inner single quotes) fixed the problem. Note that this was hard to immediately catch because when echoing both versions of the command printed to the console exactly the same.

How to connect ms sql database using perl in Windows?

I want to connect ms sql database through perl language. The following steps are I made.
I've created a database table in the name "SampleDb"
Configured ODBC and I've set name for sql server driver as "SampleDb"
Now I've tried to connect as follows,
,
my $dbs = "dbi:ODBC:DRIVER={SQL Server};SERVER={SampleDb}";
my $dbh = DBI->connect($dbs, "username", "password");
But Now I got the following error
DBI connect('DRIVER={SQL Server};SERVER={SampleDB}','username',...) failed: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (SQL-08001) [state was 08001 now 01000]
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (SQL-01000)
How to solve this ? or
How to Connect ms sql using perl through ODBC ?
This question has already been answered (and accepted !!). Just providing detailed steps for connecting MSSQL server from perl running on Linux using ODBC.
Before you get into perl stuff, you need to install and configure odbc environment on the Linux box.
Install below packages:
Fedora:
unixODBC-devel.i686
unixODBC.i686
AND
freetds.i686
freetds-devel.i686
freetds-doc.i686
Ubuntu:
unixodbc
unixodbc-dev
AND
freetds-bin
freetds-common
freetds-dev
tdsodbc
After these packages are installed we MUST be able to use freetds to test authentication network authentication with the MS SQL server.
root#ubuntu:/home# tsql -S <db_host_name> -p 1433 -U perluser -P password
locale is "en_IN"
locale charset is "UTF-8"
1>
If above fails, then check the MSSQL db permission for this user. Also check MSSQL logs. Do not proceed until you run above command successfully. Also, failure of above command has nothing to do with the unixodbc OR freetds configuration.
Configure the odbc.ini and odbcinst.ini and freetds.conf files.
/etc/odbc.ini will contain the DSN information:
root#ubuntu:/home# cat /etc/odbc.ini
[odbc-test]
Description = test
Driver = ms-sql
Servername = ms-sql
Database = <db_name>
UID = perluser
Port = 1433
Please note that, the Driver field refers to /etc/odbcinst.ini context named [ms-sql].
The Servername field refers to the /etc/freetds.conf context that I also named [ms-sql].
Database field is optional but I am using it as I want to connect to a particular Database.
/etc/odbcinst.ini file contains the Driver information:
root#ubuntu:/home# cat /etc/odbcinst.ini
[ms-sql]
Description = TDS Conection
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
UsageCount = 1
FileUsage = 1
The odbcinst.ini file simply directs the odbc.ini file to the appropriate driver.
The Driver and Setup entries for Fedora is /usr/lib/libtdsodbc.so and /usr/lib/libtdsS.so respectively.
Also, for 64-bit Linux box, it would be Driver64 and Setup64 instead of Driver and Setup respectively.
Configure /etc/freetds/freetds.conf ( /etc/freetds.conf for Fedora). It contains TDS information. Here is mine:
root#ubuntu:/home# tail /etc/freetds/freetds.conf
[ms-sql]
host = <db_host_name>
port = 1433
tds version = 7.0
dump file = /var/log/freetds.log
Please note that, above context name [ms-sql] is the value of Servername in odbc.ini.
Test the configuration by connecting the MSSQL server using isql command:
root#ubuntu:/home# isql -v odbc-test perluser password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
The odbc-test portion of the isql command was defined in the odbc.ini file.
You HAVE to receive above output which says Connected!. If you don’t, then there is some problem in your configuration and go through all the above steps again.
Now,
Install Perl DBI module.
Install DBD::ODBC module .
Then use the ODBC in your perl code as below:
my $dbh = DBI->connect ('dbi:ODBC:odbc-test', 'perluser', 'password');
Hope This Helps.
This is for connecting MSSQL using perl in Windows.
Instead of ODBC, try OLEDB. The following code will help you.
my $host = 'sample\sql';
my $database = 'SampleDB';
my $user = 'sa';
my $auth = 'password';
$dsn = "Provider=sqloledb;Trusted Connection=yes;";
$dsn .= "Server=$host;Database=$database";
my $dbh = DBI->connect("dbi:ADO:$dsn",$user,$auth,{ RaiseError => 1, AutoCommit => 1}) || die "Database connection not made: $DBI::errstr";
Reference How to connect Ms Sql using Perl

FreeBCP to SQL Azure complains table doesn't exist

$ freebcp DWSTAGE.BCPTEST in bcptest.txt -f cdr.fmt -S serverfromfreetds -U user#azureserver -P password
Msg 208, Level 16, State 1
Server 'azureserver', Line 1
Invalid object name 'DWSTAGE.BCPTEST'.
Msg 208, Level 16
General SQL Server error: Check messages from the SQL Server
Msg 20064, Level 2
Attempt to use Bulk Copy with a non-existent Server table
$ freebcp DATABASENAME.DWSTAGE.BCPTEST in bcptest.txt -f cdr.fmt -S serverfromfreetds -U user#azureserver -P password
Msg 40515, Level 15, State 1
Server 'azureserver', Line 16
Reference to database and/or server name in 'DATABASENAME.DWSTAGE.BCPTEST' is not supported in this version of SQL Server.
Msg 40515, Level 15
General SQL Server error: Check messages from the SQL Server
Msg 20064, Level 2
Attempt to use Bulk Copy with a non-existent Server table
I've also tried adding the database to the command line with the -D option. The default database for that connection is set up as this one and only Azure database in the freetds.conf.
The connection to SQL Azure seems fine otherwise - I just can't get FreeBCP to work:
$ isql serverfromfreetds user#azuredatabasename password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> SELECT COUNT(*) FROM DWSTAGE.BCPTEST;
+------------+
| |
+------------+
| 0 |
+------------+
SQLRowCount returns 1
1 rows fetched
SQL> SELECT COUNT(*) FROM DWSTAGE.BCPTESTX;
[ISQL]ERROR: Could not SQLExecute
SQL>
This seems like some database/schema confusion, but I can't find a combination of settings which works.
From the FreeTDS mailing list:
The message 208 comes from the server. A quick look at freebcp.c shows
argv[1] isn't parsed. It's copied to a struct and used verbatim e.g.
if (dbfcmd(dbproc, "SET FMTONLY ON select *
from %s SET FMTONLY OFF", pdata->dbobject) == FAIL)
My guess is that the account you're logging in with has a default
database, and that database is not the one containing DWSTAGE.BCPTEST.
The Azure server rejects dbname.schema.object syntax, and freebcp has
no -D option because until Azure every TDS server did accept that
syntax.
You could verify that using
$ freebcp 'select db_name()' queryout /dev/stdout ...
As a temporary workaround, I think this would work:
freebcp DWSTAGE.BCPTEST in bcptest.txt \
-O 'USE dbname' \
-f cdr.fmt -S serverfromfreetds -U user#azureserver -P password
A permanent fix would support -D.
Yes, that user's default database is probably master. There IS a
default database set up in the odbc config, but I was mistaken, there
is no such option in the freeetds.conf.
We've moved away from trying to get Linux to work for this process for
now, but I'll revisit this.
I expect that workaround will not work because USE isn't supported -
you do in fact have to connect directly to the database, because of
the nature of the SQL Azure architecture.
Yes, you're right. I forgot about that.
About a year ago we added the DBSETLDBNAME macro as a way to set the
dbname in the db-lib LOGINREC. That sets the dbname in the login
packet, obviating the need for "USE dbname". freebcp could be modified
to support that feature with a -D option.
See change
http://gitorious.org/freetds/freetds/commit/4a21ded022405693607e71938d0c6173816f5ff9/diffs/c34afafd2fec4cbba9b245e4f13a5471c6fb8041
(add support for -D in freebcp)
I have gotten freebcp working with Ubuntu 12.04 and Azure SQL. It follows on to the answer above where support for -D is mentioned.
First I started by installing and configuring freetds as described in this thread: https://askubuntu.com/questions/167491/connecting-ms-sql-using-freetds-and-unixodbc-isql-no-default-driver-specified
Basically, that consisted of:
sudo apt-get install tdsodbc unixodbc freetds-bin
That brought me to the point where this thread starts; freebcp could connect but I was getting the error about "Reference to database...not supported in this version of SQL server".
The next step is to note that the version of freebcp installed by apt-get is a quite old version. Instead download a more recent version from ftp://ftp.freetds.org/pub/freetds/stable/. I used freetds-1.00.9.tar.gz.
Install it using ./configure and make then use this new freebcp just the same but with -D.
Here is my command string: freetds-1.00/src/apps/freebcp bcptest in bcptest.big.dat -U myUserName#myServer -S MyServerConfig -P 'mypa$$word' -D myDatabase -c -e upload.err

Connecting to SQL Server with ActiveRecord

Have you ever had to connect to SQL Server with ActiveRecord? Is this possible? Can anyone provide some starting points?
This what I used:
From here:
http://github.com/rails-sqlserver/2000-2005-adapter/tree/master
Installation
First, you will need Ruby DBI and Ruby ODBC. To my knowledge the ADO DBD for DBI is no longer supported. The installation below is not a comprehensive walk thru on how to get all the required moving parts like FreeTDS installed and/or configured. It will also assume gem installations of both the dependent libraries and the adapter itself.
It should be noted that this version of the adapter was developed using both the ancient 0.0.23 version of DBI up to the current stable release of 0.4.0. Because later versions of DBI will be changing many things, IT IS HIGHLY RECOMMENDED that you max your install to version 0.4.0 which the examples below show. For the time being we are not supporting DBI versions higher than 0.4.0. The good news is that if you were using a very old DBI with ADO, technically this adapter will still work for you, but be warned your path is getting old and may not be supported for long.
$ gem install dbi --version 0.4.0
$ gem install dbd-odbc --version 0.2.4
$ gem install rails-sqlserver-2000-2005-adapter -s http://gems.github.com
From here: http://lambie.org/2008/02/28/connecting-to-an-mssql-database-from-ruby-on-ubuntu/
Firstly, update your ~/.profile to include the following:
export ODBCINI=/etc/odbc.ini
export ODBCSYSINI=/etc
export FREETDSCONF=/etc/freetds/freetds.conf
Then reload your .profile, by logging out and in again.
Secondly, on Ubuntu 7.10 Server I needed to install some packages.
mlambie#ubuntu:~$ sudo aptitude install unixodbc unixodbc-dev freetds-dev sqsh tdsodbc
With FreeTDS installed I could configure it like this:
mlambie#ubuntu:/etc/freetds$ cat freetds.conf
[ACUMENSERVER]
host = 192.168.0.10
port = 1433
tds version = 7.0
The important thing here is ACUMENSERVER, which is the DSN that I’ll use when connecting to the database. The host, and port are self-explanatory, and it’s worth noting that I had to use 7.0 specifically as the tds version.
Testing FreeTDS is not too hard:
mlambie#ubuntu:~$ sqsh -S ACUMENSERVER -U username -P password
sqsh: Symbol `_XmStrings' has different size in shared object, consider re-linking
sqsh-2.1 Copyright (C) 1995-2001 Scott C. Gray
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
1> use acumen
2> go
1> select top 1 firstname, lastname from tblClients
2> go
[record returned]
(1 row affected)
1> quit
Next up it’s necessary to configure ODBC:
mlambie#ubuntu:/etc$ cat odbcinst.ini
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1
mlambie#ubuntu:/etc$ cat odbc.ini
[ACUMENSERVER]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = ACUMENSERVER
Database = ACUMEN
I then tested the connection with isql:
mlambie#ubuntu:~$ isql -v ACUMENSERVER username password
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> use ACUMEN
[][unixODBC][FreeTDS][SQL Server]Changed database context to 'Acumen'.
[ISQL]INFO: SQLExecute returned SQL_SUCCESS_WITH_INFO
SQLRowCount returns -1
SQL> select top 1 firstname from tblClients;
[record returned]
SQLRowCount returns 1
1 rows fetched
SQL> quit
OK, so we’ve got ODBC using FreeTDS to connect to a remote MSSQL server. All that’s left is to add Ruby into the mix.
mlambie#ubuntu:~$ sudo aptitude install libdbd-odbc-ruby
The last thing to test is that Ruby can use DBI and ODBC to hit the actual database, and that’s easy to test:
mlambie#ubuntu:~$ irb
irb(main):001:0> require "dbi"
=> true
irb(main):002:0> dbh = DBI.connect('dbi:ODBC:ACUMENSERVER', 'username', 'password')
=> #<DBI::DatabaseHandle:0xb7ac57f8 #handle=#<DBI::DBD::ODBC::Database:0xb7ac5744
#handle=#<odbc::database:0xb7ac576c>, #attr={}>, #trace_output=#</odbc::database:0xb7ac576c><io:0xb7cbff54>,
#trace_mode=2>
irb(main):003:0> quit
And a more complete test (only with SQL SELECT, mind you):
#!/usr/bin/env ruby
require 'dbi'
db = DBI.connect('dbi:ODBC:ACUMENSERVER', 'username', 'password')
select = db.prepare('SELECT TOP 10 firstname FROM tblClients')
select.execute
while rec = select.fetch do
puts rec.to_s
end
db.disconnect
</io:0xb7cbff54>
From here (to fix the odbc lib being in the wrong place):
http://ubuntuforums.org/showthread.php?t=433435&page=2
libtdsodbc.so
with freeTDS (freetds-dev, tdsodbc), you can either edit the path in the odbcinst.ini file for the [FreeTDS] driver section OR cp the /usr/lib/odbc/libtdsodbc.so into /usr/lib/libtdsodbc.so.
either way works when accessing mssql from the prompt
isql -v $dsn $user $passwd
i found this to be useful
http://www.unixodbc.org/doc/FreeTDS.html#Configuration
And then in the database.yml file:
development:
adapter: sqlserver
mode: odbc
dsn: dsn_name
username: my_username
password: my_password
These are the steps i've compiled for Centos 5.3. It took me a lot of trial and error to get this working. It's from a completely clean Centos installation.
Install EPEL:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
Install ruby, rubygems, freetds, unixODBC, development tools:
yum install gcc
yum install freetds
yum install ruby-devel
yum install unixODBC-devel
yum install ruby rubygems
Install rails:
gem install rails
Install DB related gems:
gem install dbd-odbc
gem install rails-sqlserver-2000-2005-adapter -s http://gems.github.com
Download, build and install ruby-odbc:
wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9997.tar.gz
tar zxvf ruby-odbc-0.9997.tar.gz
cd ruby-odbc-0.9997
ruby extconf.rb
make
make install
Final gem list:
# gem list
*** LOCAL GEMS ***
actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
dbd-odbc (0.2.4)
dbi (0.4.1)
deprecated (2.0.1)
rails (2.3.2)
rails-sqlserver-2000-2005-adapter (2.2.17)
rake (0.8.7)
You can use various tools like isql to test your ODBC connection. Brian's post covers this in nice detail so I won't repeat. In rails you need a database.yml that looks something like this:
development:
adapter: sqlserver
mode: odbc
dsn: dsnName
username: username
password: password
On Ubuntu, I use FreeTDS and the activerecord-sqlserver-adapter gem.
You can install FreeTDS through apt:
sudo apt-get install freetds
And add this to your Gemfile:
gem 'activerecord-sqlserver-adapter'
I had to change the configured FreeTDS version number in /etc/freetds/freetds.conf to 8.0 in order to get things working correctly.
[global]
tds version = 8.0
activerecord-sqlserver-adapter on GitHub
FreeTDS project

Resources