Connect to a Sybase database in Python without a DSN?

Question:

I’m trying to connect to a Sybase database in Python (using the python-sybase DBAPI and sqlalchemy module), and I’m currently receiving the following error:

ct_connect(): directory service layer: internal directory control layer error: There was an error encountered while binding to the directory service

Here’s the code:

import sqlalchemy
connect_url = sqlalchemy.engine.url.URL(drivername='pysybase', username='read_only', password='*****', host='hostname', port=9000, database='tablename', query=None)

db = sqlalchemy.create_engine(connect_url)
connection = db.connect()

I’ve also tried to connect without sqlalchemy – ie, just importing the Python Sybase module directly and attempting to connect, but I still get the same error.

I’ve done quite a bit of googling and searching here on SO and at the doc sites for each of the packages I’m using. One common suggestion was to verify the DSN settings, as that’s what’s causing ct_connect() to trip up, but I am able to connect to and view the database in my locally-installed copy of DBArtisan just fine, and I believe that uses the same DSN.

Perhaps I should attempt to connect in a way without a DSN? Or is there something else I’m missing here?

Any ideas or feedback are much appreciated, thank you!

Asked By: ignorantslut

||

Answers:

I figured out the issue for anyone else who might be having a similar problem.

Apparently, even though I had valid entries for the hostname in my sql.ini file and DSN table, Sybase was not reading it correctly – I had to open DSEdit (one of the tools that comes with Sybase) and re-enter the server/hostname info.

Answered By: ignorantslut