1

First of all thank you for your help.

I was trying to retrieve some data from a sybase IQ database using python, but I can not make it.

I've tried with the following code( from https://github.com/sqlanywhere/sqlanydb):

import sqlanydb
conn = sqlanydb.connect(uid='dba', pwd='sql', eng='demo', dbn='demo' )
curs = conn.cursor()
curs.execute("select 'Hello, world!'")
print( "SQL Anywhere says: %s" % curs.fetchone() )
curs.close()
conn.close()

Unfotunately it gives me the following error:

InterfaceError: ('Could not load dbcapi.  Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)

Does anyone know how to fix it?

Thanks in advance

Jessica

Jessica
  • 11
  • 3

2 Answers2

2

On windows, first you need to add the data source name (DSN).

You do this by searching for 'odbc data source administrator' on windows and creating a DSN for 'SQL Anywhere 12'. Fill in the necessary information like username,password,host,port,server name and database name. Finally test the connection as shown.

enter image description here

Once finished you can call the code as follows:

import sqlanydb

conn = sqlanydb.connect(dsn='SYBASE_IQ')
curs = conn.cursor()
curs.execute("select 'Hello, world!'")
print( "SQL Anywhere says: %s" % curs.fetchone())
curs.close()
conn.close()
Danjel
  • 71
  • 1
  • 7
0
  1. Get and install the SYBASE ODBC DRIVER.
  2. Configure the DSN on your PC.

On Windows, search for the Microsoft ODBC Administrator. Then create a DSN.

Select the driver

Configure DSN attributes

  1. Python code:

    • using SQLAchemy

      import sqlalchemy as sa
      from sqlalchemy import create_engine, event
      from sqlalchemy.engine.url import URL
      import urllib
      
      params = urllib.parse.quote_plus('DSN=dsn_name;PWD=user_pwd')
      engine = sa.create_engine("sybase+pyodbc:///?odbc_connect={}".format(params))
      
      with engine.connect() as cursor:
      
           cursor.execute(""" SELECT * FROM database """)
      
    • Using PyODBC

      import pyodbc
      
      conn = pyodbc.connect('DSN=dsn_name;PWD=user_pwd')
      
      with conn:
           cursor = conn.cursor()   
           cursor.execute(""" SELECT * FROM database """)
      
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343