Alan Zavala
Alan Zavala

Reputation: 21

PyODBC SQL Anywhere 17 Conect to Sybase Kernel Dies

I am Working on Ubuntu 18.04 when I am using Pyodbc connection with SQL Anywhere 17 Driver to connect to a Sybase DB, while trying to establish connection my Jupyter notebook Dies. The expectation is, I should be able to run this code in Ubunt and connect to a Sybase DB.

I can connect and run query from Windows without problems(using DSN).

I have been working with other driver and SQL Server, MySQL and MariaDB and I have not encountered any problems. I believe connection to Sybase database needs SQLANYWHERE DRVIER.

If Someone knows how get the connection string which is passed from pyodbc to the server when I use a DSN?(maybe this could give me an idea to know what i'm doing wrong).

Some advice?

Code run in windows without problems

import pyodbc
import pandas as pd

cnxn = pyodbc.connect("DSN=RevDSN")
print(cnxn)
data = pd.DataFrame(pd.read_sql_query(query, cnxn))
cnxn.close()

Upvotes: 0

Views: 1810

Answers (1)

Stephen Hamel-Smith
Stephen Hamel-Smith

Reputation: 1

Since I didn't find a good explanation I am putting this here.

I installed the client from

https://archive.sap.com/documents/docs/DOC-35857

then followed the basic instructions from

https://wiki.scn.sap.com/wiki/display/SQLANY/Installing+SQL+Anywhere+17+on+Ubuntu+14.04

The ODBC Client will not ask for the keys

As the documentation says the important part is running the sa_config.sh and making sure that the exports happen.

Lastly edit the /etc/odbcinst.ini file and add the driver.

For example

[SQL Anywhere 17]
Driver=/opt/sqlanywhere17/lib64/libdbodbc17.so
TDS_Version=5.0
UsageCount=1

Then I used this connection string

import pyodbc
cnxn = pyodbc.connect('Driver={SQL Anywhere 17};LINKS=TCPIP{HOST=<server ip here>};PORT=2638;UID=admin;PWD=<password here>;ENG=<engine name>;DBN=<database name>;')
cursor = cnxn.cursor()
cursor.execute("select top 10 * from dba.<table name>") 
for row in cursor:                                                                   
     print(row) 

And it worked.

Upvotes: 0

Related Questions