Brian K
Brian K

Reputation: 61

sqlanydb windows could not load dbcapi

I am trying to connect to a SQL Anywhere database via python. I have created the DSN and I can use command prompt to connect to the database using dbisql - c "DNS=myDSN". When I try to connect through python using con = sqlanydb.connect(DSN= "myDSN") I get

`Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    con = sqlanydb.connect(DSN= "RPS Integration")
  File "C:\Python27\lib\site-packages\sqlanydb.py", line 522, in connect
    return Connection(args, kwargs)
  File "C:\Python27\lib\site-packages\sqlanydb.py", line 538, in __init__
    parent = Connection.cls_parent = Root("PYTHON")
  File "C:\Python27\lib\site-packages\sqlanydb.py", line 464, in __init__
    'libdbcapi_r.dylib')
  File "C:\Python27\lib\site-packages\sqlanydb.py", line 456, in load_library
    raise InterfaceError("Could not load dbcapi.  Tried: " + ','.join(map(str, names)))
InterfaceError: (u'Could not load dbcapi.  Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)`

Upvotes: 5

Views: 7539

Answers (4)

andresd27
andresd27

Reputation: 1

I was stoked in this same problem, both windows system32 and 64.

I'm using Python 3.9 and I found that since Python 3.8 the cdll.LoadLibrary function does no longer search PATH to find library files.

To fix this, I created the enviroment variable SQLANY_API_DLL pointing to the route of sqlanywhere installation, in my case version 17, bin32 or bin64 depending on your system.

Upvotes: 0

VLRoyrenn
VLRoyrenn

Reputation: 786

Depending on how Sybase is locally installed, it could also be that the Python module really cannot find the (correct) library when looking up dbcapi.dll in your PATH. A quick fix for that is to create a new SQLANY_API_DLL environment variable (that's the initial None in the names the error message says it tried using; it takes priority over all the others) containing the correct path, usually something like %SQLANY16%\Bin64\dbcapi.dll depending on what version you have installed (Sybase usually creates an environment variable pointing to its installation folder on a per version basis).

Upvotes: 1

SnoopyLane
SnoopyLane

Reputation: 189

One way to encounter the backtrace shown by the OP is running 64-bit Python interpreter, which is unable to load the 32-bit dbcapi.dll. Try launching with "py -X-32" to force a 32-bit engine, or reinstall using a 32-bit python engine.

Unfortunately sqlanydb's code that tries to be smart about finding dbcapi also ends up swallowing the exceptions thrown during loading. The sqlanydb author probably assumed that failure to load implies file not found, which isn't always the case.

Upvotes: 0

Brian K
Brian K

Reputation: 61

I was able to resolve the problem. I was never able to use the sqlanydb.connect. I ended up using pyodbc. So my final connection string was con = pydobc.connect(dsn="myDSN"). I think that sqlanydb is only fully functional with sqlanydb 17 and I was using a previous version.

Upvotes: 1

Related Questions