How to connect to Pervasive SQL server in Ruby Application? - ruby

I am trying to connect to a Pervasive Sql Server which is running on Windows machine from my Ruby application which is on Ubuntu Machine. Can Someone please help me on same. Thanks in advance
Below is my configuration on linux machine
/etc/freetds/freetds.conf
[pserver]
host = XXX.XXX.XX.XXX
port = 1583
tds version = 8.0
Under /etc/odbcinst.ini, I have saved the driver info like below
[freetds]
Description=freetds Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Trace=Yes
TraceFile=/tmp/freetds.log
ForceTrave=Yes
UsageCount=10
fileusage=1
dontdlclose=1
TDS_Version = 8.0
In /etc/odbc.ini, client and database details
[pclient]
Description = Pervasive SQL Server
Driver = freetds
Trace = Yes
Servername = pserver
Port = 1583
Database = "MyDatabasename"
TDS_Version = 8.0
tsql -S pserver -U db_username -P db_password -d MyDatabasename
above cmd gives error saying
Error 20009 (severity 9):
Unable to connect: Adaptive Server is unavailable or does not exist
OS error 111, "Connection refused"
There was a problem connecting to the server
iodbctest ["DSN=pclient;UID=db_username;PWD=db_password"]
this results in
iODBC Demonstration program
This program shows an interactive SQL processor
Driver Manager: 03.52.0812.0326
(iodbctest:6672): Gtk-WARNING **: 20:40:38.693: cannot open display:
Not able to understand the above result and how to handle this. Please help

As far as I know, the only way to access Pervasive PSQL from Ruby would be through ODBC. You need to use the Pervasive Client ODBC driver. Don't use the FreeTDS driver. I've never heard of using the FreeTDS driver to connect to Pervasive PSQL. In fact, this question mentions that FreeTDS doesn't work to Pervasive PSQL. Pervasive PSQL and Microsoft SQL Server are not the same product and the client for one cannot connect to the server of the other.
The short answer would be to install the Pervasive PSQL client on the Ubuntu machine, create the ODBC Datasource name pointing to the database on the Windows machine and then use ODBC from within Ruby to access the data.
You'll want to be on at least Pervasive PSQL v11.30, preferably Actian PSQL v13 (current version as of December 2018). You'll need to download and install the client appropriate for the application. If the Ruby application is 32 bit, you need the 32 bit ODBC driver. If the application is 64 bit, you'll need the 64 bit driver. The 'bitness' of the OS is not as important. You need to use the same PSQL client version as server version. You cannot use the v13 client with a v11 server.

Related

How to create ODBC "DSN" for cross-platform testing?

I need a simple ODBC test scenario on WIN which I can configure very simply and be assured it is working in support of another question at Unix.SE.
In a nutshell I'm trying to setup a PyODBC/Python script connection from Debian 10 (192.168.1.2) to Windows 10 in KVM/QEMU virtual system (192.168.1.12).
First, on the Windows 10/KVM, I see the ODBC Data Source Administrator has a tab File DSN and Microsoft Text Driver. Can I use FileDSN to test Python PyODBC connection to ODBC using a simple CSV file in place of Server?? (My research with ODBC only finds running server instances).
Next, what I tried:
On Debian I installed ODBC Microsoft driver for Linux.
Shutdown the Windows 10 firewall, and I can ping in both directions:
$nmap -p 22 192.168.1.12 # Deb to Win
> Test-NetConnection 192.168.1.2 -p 22 # Win to Deb
On Windows 10/KVM I added a FileDSN with Microsoft Text Driver. I created a CSV file (odbc_test_01.csv) with simple header and one row of data (IE. {'ID' : 1, 'NAME' : 'FOO'})
Created a Jupyter Notebook to make testing easier. Here is my connection string and the results:
cn = pyodbc.connect(r'Driver={ODBC Driver 17 for SQL Server};' # Driver installed above
r'FILEDSN=odbc_test_01.csv;' # my attempt at FileDSN
r'SERVER=192.168.1.12;' # KVM IP tested with ping
r'Trusted_Connection=no;' # explicit; use UID/PWD
r'UID=<username>;' # Windows user name
r'PWD=<password>', # Windows user password
autocommit=True)
OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
Tried isql from Debian command line with same string:
isql -v -k ''Driver={ODBC Driver 17 for SQL Server};FILEDSN=odbc_test_01.csv;SERVER=192.168.1.12; Trusted_Connection=no;UID=<username>;PWD=<password>'
Similar pages here at SO:
Authenticate from Linux to Windows SQL Server with pyodbc
Python pyodbc connect to Sql Server using SQL Server Authentication
An ODBC "File DSN" is not a driver for accessing data in a file. It is a way to specify a DSN (connection information for a target database) as values in a standalone file instead of in a standard configuration file on Linux (e.g., /etc/odbc.ini) or in the Windows registry.
If you need to "clone" a Windows DSN entry for use in a Linux environment then you may find my dump_dsn utility helpful. It retrieves an ODBC DSN from the Windows registry and presents it in a form that you could use to recreate the DSN on Linux.
For example, say I had a DSN named "mssql199" on Windows and when I ran dump_dsn.to_text("mssql199") on it I got
[mssql199]
Driver=ODBC Driver 17 for SQL Server
Description=with UseFMTONLY
Server=192.168.0.199
Database=myDb
Encrypt=No
TrustServerCertificate=No
ClientCertificate=
KeystoreAuthentication=
KeystorePrincipalId=
KeystoreSecret=
KeystoreLocation=
UseFMTONLY=Yes
Trusted_Connection=No
To use that same DSN on a Linux box I would have to
copy that block into /etc/odbc.ini (or equivalent, for a "System DSN") or ~/.odbc.ini (for a "User DSN") to use DSN=mssql199, or
save that block with an [ODBC] header instead of [mssql199] to a file, e.g., /home/gord/mssql199_file.dsn (for a "File DSN") and use FILEDSN=/home/gord/mssql199_file.dsn
Edit re: "Can I use FileDSN to test Python PyODBC connection to ODBC using a simple CSV file in place of Server??"
No. An ODBC DSN or FILEDSN on the Windows box will only be useful to connect from the Windows box to a data source (either locally, or on some other machine). We cannot connect from one machine (e.g., Linux) to an ODBC DSN entry on another machine
I created an SQLite database. Then I added SQLite drivers for ODBC.

How to install IBM db2 cli drivers on mac osx mojave

In order to use db2 with node.js on my mac. I have installed the db2 drivers - DB2 v11.1.4.5.
I also configured my environment paths so that the correct config files will be used by unixODBC
I configured the odbcinst.ini, ODBC.ini , db2cli.ini, and the db2dsdriver.cfg files
The issue is that I get the error below when I run the iqsl command or the db2cli validate command
My Error
[S1000][unixODBC][IBM][CLI Driver] SQL10007N Message "0" could not be retrieved. Reason code: "3".
unixODBC isql command syntax
isql usrProd userid password
db2cli validate command syntax
db2cli validate -dsn alias -connect -user userid -passwd password
Environment path stored in file ~/.bash_profile
export PATH=$PATH:/usr/local/share/odbc_db2/clidriver/bin/
export DB2CLIINIPATH=/usr/local/share/odbc_db2/clidriver/cfg/
export DB2DSDRIVER_CFG_PATH=/usr/local/share/odbc_db2/clidriver/cfg/
I have been documenting the steps that I took to install the db2 command line drivers.
My documentation
locations of the IBM DB2 Drivers I have installed:
Client Version (level/bit): DB2 v11.1.4.5 (special_39510/64-bit)
Client Version (level/bit): DB2 v11.1.1.1 (s1703232000/64-bit)
UPDATE --- 20200413----
I got it to work on my Mac. I did get it to work with Node.js
I contacted a few IBM developers who are working directly on this project, and they gave me access to the proper "IBM i Access ODBC Driver" to connect to the as400 from the mac.
It is being beta tested now. At some point, it should be released. to the general public.
db2cli drivers are not needed, db2cli.ini is not needed:
IBM has specific odbc drivers for the iseries. I dont have permission
to share the drivers with the public, but do know that it will be
possible soon for everyone to connect to db2 installed on the iseries
I got it to work on my Mac and I did get it to work with Node.js
I contacted a few IBM developers who are working directly on this project, and they gave me access to the proper "IBM i Access ODBC Driver" to connect to the as400 from the mac. It is being beta tested now, i assume that at some point, it should be released to the general public.
Note : db2cli drivers are not needed, db2cli.ini is not needed, and setting environment paths are not needed:
IBM has specific odbc drivers for the iseries. I don't have permission
to share the drivers with the public, but do know that it will be
possible soon for everyone to connect to db2 installed on the iseries
For IBM DB2 Warehouse on the IBM CLoud you can go to this url
https://your_tenant.cloud.ibm.com/console/#connection/overview
In above replace your_tenant with your tenant id.

Ruby/PG - Cannot connect to PostgreSQL

I've setup a new Linux Subsystem (Ubuntu) on Windows to run Ruby scripts, but the PG gem cannot connect to my PostgreSQL server. It seems like I can connect just fine using psql in the terminal (I think), but not using irb.
Problem:
If I run the following in IRB (within the Linux subsystem shell):
require 'pg'
PG.connect(:dbname=>"postgres")
I get the following error:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
However, if I use psql to to select the version(), it returns that just fine:
psql -p 5432 -h localhost -U postgres
postgres=# select version();
Returns:
PostgreSQL 10.1 on x86_64-pc-mingw64, compiled by gcc.exe (Rev5, Built by MSYS2 project) 4.9.2, 64-bit (1 row)
I should mention that I installed Postgres in my Windows environment, and not within the Linux subsystem - however, due to limitations in the subsystem, this seems to be the only way to do it from what I've read online.
I'm not sure if this belongs here or on Superuser or the unix/ubuntu SE, but my basic troubleshooting indicates that this is a problem with Ruby/pg gem, not the subsystem, so I'm posting my question here first.
The default connection is UNIX socket (a quasi-file, as you can see by the error message, /var/run/postgresql/.s.PGSQL.5432), not TCP socket (host:port). Pass your host/port explicitly to PG.connect.
PG.connect(dbname: "postgres", host: 'localhost', port: 5432)

Connecting to MS SQL server from Mac OS 10.7 through python

I'm on Mac OS 10.7.5 . I want to connect to an MS SQL db from python2.7. To connect, I've installed and configured FreeTDS and unixodbc. After these, I've installed pyodbc 3.0.10 library through pip.
In the previous versions, pyodbc on Mac installations were compiled to use iODBC, so to make the pyodbc module use unixodbc, some modifications needed to be done before compiling the module. But the later versions (including 3.0.10) are compiled to use unixodbc by default.
After configurations, I've managed to connect to the db using isql, which shows that my unixodbc configurations are in order. But when I try to connect to the db on python as follows;
pyodbc.connect('DSN=DSN;UID=USER;PWD=PASS')
I get the following error:
pyodbc.Error: ('IM002', '[IM002] [iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded (0) (SQLDriverConnect)')
Looks like it is trying to use iODBC. What could be causing this?
EDIT: My config files:
freetds.conf:
[SERVERNAME]
host = DBID.database.windows.net
tds version = 7.1
port = 1433
odbcinst.ini
[FreeTDS]
Description = FreeTDS
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
odbc.ini
[DSN]
Description = "DESC"
Driver = FreeTDS
Servername = SERVERNAME
Port = 1433
Database = DBNAME
I've always had better luck connect directly with options:
pyodbc.connect('DRIVER={FreeTDS};SERVER=dbserver.domain.com;PORT=1433;DATABASE=yourdb;UID=youruser;PWD=yourpassword;TDS_Version=7.2;')
Can you give that a try? If that doesn't work, please include your freetds.conf, odbc.ini and odbcinst.ini files so we can repro. Good luck!

ODBC Driver Manager: Data source name not found and no default driver specified

I am setting up Go, FreeTDS, and unixODBC on OSX. I followed the instructions on https://code.google.com/p/odbc/wiki/InstallingUnixODBCOnOSX, and when I tried to run the tests, I get:
[ODBC Driver Manager] Data source name not found and no default driver specified
The port installs both unixODBC and FreeTDS, so what is needed to resolve this problem?
In my opinion, the best way to do is to use a DSN-less configuration — when you encode full information required to connect to a server instance in the ODBC connection string. The upside of this approach is that it requires exactly zero configuration of the client machine, other than making sure the FreeTDS ODBC driver is properly installed.
Note two caveats applicable to FreeTDS in this sort of setup though:
You have to use the Port connection string key. It's typically 1433 if you're connecting to a Microsoft® SQL Server™.
FreeTDS has an insanely low default TDS protocol version — something like 5.0.
To override this, you have to use the TDS_Version connection string key. Either set it to auto or to a some sensible value:
Microsoft® SQL Server™ 7.0 → 7.0
〃 2000 → 7.1
〃 2005 → 7.2
〃 2008 → 7.3
〃 2012 → 7.4
Looks like 7.2 is the largest TDS protocol version currently supported by FreeTDS but actually 7.2 is more than enough to work with typical data types, including varbinary(max).
In Linux you use odbcinst to register the data source, but you need to know where libtdsodbc.so is
On my Mac, it was put in
/opt/local/lib/libtdsodbc.so
If that's not where yours was installed, do this to find its location:
sudo find / -name "libtdsodbc.so"
Then create a file called "tds.driver.template" with the following inside:
[FreeTDS]
Description = Open source FreeTDS Driver
Driver =/opt/local/lib/libtdsodbc.so
Then run
sudo odbcinst -i -d -f tds.driver.template
I was running into this issue, and I think what fixed it was setting the ODBCSYSINI and ODBCINI environment variables (credit to this answer). For Mac, you need to set them to these values:
export ODBCSYSINI=/Library/ODBC
export ODBCINI=/Library/ODBC/odbc.ini

Resources