Connecting to MS SQL server from Mac OS 10.7 through python - macos

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!

Related

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.

How to connect to Pervasive SQL server in Ruby Application?

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.

Filemaker ODBC Python Connection issues Mac os 10.12.02

I'm trying to set up pyodbc on a mac so I can run python scripts to talk to a filemaker database.
I am running python2.7
I have installed ODBC Manager, and the Filemaker odbc client driver. I have tested this connection and it connects fine.
However when I run the python script i get this error
pyodbc.Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib 'FileMaker ODBC' : file not found (0) (SQLDriverConnect)")
c = "DRIVER={FileMaker ODBC};SERVER=localhost:2399;DSN=DB;UID=user;PWD=pass;Trusted_Connection=yes"
con = pyodbc.connect(c)
Any help would be really appreciated.
Problem fixed. My odbc.ini file was in the wrong place.
I ran the command
odbcinst -j
unixODBC 2.3.5
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
and moved the odbc.ini file from /Library/ODBC/odbc.ini to /usr/local/etc/odbc.ini
problem solved.
Other options:
PyFileMaker - using XML API
https://github.com/aeguana/PyFileMaker
bBox - plugin
https://bbox.beezwax.net/products/bbox
Python-fmrest - using FM Data API
https://github.com/davidhamann/python-fmrest

HIVE ODBC connector settings

I configured unixodbc to use the hive connector from cloudera in my Linux Mint machine,
but I keep receiving the following error when trying to connect to hive (e.g. using isql -v hive)
S1000][unixODBC][Cloudera][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function.
[ISQL]ERROR: Could not SQLConnect
I think I set the /etc/odbcinst.ini and the ~/.odbc.ini in the correct way:
# content of /etc/odbcinst.ini
[hive]
Description = Cloudera ODBC Driver for Apache Hive (64-bit)
Driver=/opt/cloudera/hiveodbc/lib/64/libclouderahiveodbc64.so
ODBCInstLib=libodbcinst.a(libodbcinst.so.1)
UsageCount = 1
DriverManagerEncoding=UTF-16
ErrorMessagesPath=/opt/cloudera/hiveodbc/ErrorMessages/
LogLevel=0
SwapFilePath=/tmp
and my ~/.odbc.ini file contains:
[hive]
Description=Cloudera ODBC Driver for Apache Hive (64-bit) DSN
Driver = hive
ErrorMessagesPath=/opt/cloudera/hiveodbc/ErrorMessages/
# Values for HOST, PORT, KrbHostFQDN, and KrbServiceName should be set here.
# They can also be specified on the connection string.
HOST= <the host>
PORT= <the port>
Schema=<the schema>
# .. etc
Can you help me find out what is causing the error?
What does
ldd /opt/cloudera/hiveodbc/lib/64/libclouderahiveodbc64.so
Show you?
It may be that the driver is not linked to libodbcinst.so.
You could try a
LD_PRELOAD=/usr/local/libodbcinst.so
or wherever libodbcinst.so is on your machine.
Are you sure that you ODBCInstLib is set properly?
I was hitting the same issue with a Vertica driver and my libodbcinst.so.1 ended up needing an absolute path: /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
I determined the path by running a Find for libodbcinst.so.

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