Hi all,

I try to connect to a SQL17 DB using the following lines in Python

import sqlanydb

con = sqlanydb.connect(uid='dba', pwd='sql', servername='SRV1', host='localhost:2638' )

con.close()

I get following errors:

File "C:\Python38\lib\site-packages\sqlanydb.py", line 522, in connect

File "C:\Python38\lib\site-packages\sqlanydb.py", line 538, in init parent = Connection.cls_parent = Root("PYTHON")

self.api = load_library(os.getenv( 'SQLANY_API_DLL', None ), 'dbcapi.dll', 'libdbcapi_r.so',

raise InterfaceError("Could not load dbcapi. Tried: " + ','.join(map(str, names))) sqlanydb.InterfaceError: ('Could not load dbcapi. Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)

asked 05 Oct '20, 14:31

Baron's gravatar image

Baron
2.1k134146175
accept rate: 46%

Has Google banned you? https://sqlanywhere-forum.sap.com/questions/23704/python3-cannot-import-sqlanydb

Can you simply tell us, what answer you have found, and what you have tried before you raised the question?

(05 Oct '20, 17:54) Vlad
Replies hidden
(06 Oct '20, 02:17) Baron

I reinstalled my SQLAnywhere17, and now I have both 32/64, and I see the file dbcapi.dll is located under C:\Program Files (x86)\SQL Anywhere 17\BIN32, but I still get the same error

(06 Oct '20, 02:32) Baron
Replies hidden

Well, when your are running on Windows, links to Unix issues (like "sourcing" scripts) won't help, methinks...

Have you followed these steps, and have they proved successful?

(06 Oct '20, 03:34) Volker Barth

Yes, I did the steps before.

import ctypes doesn't return any error.

I installed sqlanydb using pip install sqlanydb

(06 Oct '20, 03:41) Baron

@vlad does it work on your windows machine?

(06 Oct '20, 06:27) Baron
showing 2 of 6 show all flat view

"Now it works with the help of PYODBC"..... here's how to do a DSN-less connection. Not too hard...

Assume> dbsrv17 -n demo17 "C:\Users\Public\Documents\SQL Anywhere 17\Samples\demo.db" -n demo

!!!Code starts....

import pyodbc

connection_string = "Driver=SQL Anywhere 17;Server=demo17;UID=dba;PWD=sql;DBN=demo"

connection_object = pyodbc.connect(connection_string)

cursor = connection_object.cursor()

sql_string = "select count(*) from Employees"

result = cursor.execute(sql_string)

counter = result.fetchone()[0]

print(counter)

connection_object.close()

!!! Code ends

HTH, Paul

BTW how do you put a code block in these answer boxes? I tried pre and code tags as per help and it previewed OK but when posted looked horrid. I then had to cut out all my enlightning comments!

permanent link

answered 10 Oct '20, 19:31

PaulSlater's gravatar image

PaulSlater
512
accept rate: 100%

edited 16 Feb '21, 03:42

Volker%20Barth's gravatar image

Volker Barth
40.1k361549819

Thank you very much for the answer. It worked on my machine without DSN and even without service:

connection_string = "Driver=SQL Anywhere 17;UID=dba;PWD=sql;DBF=C:\Users\Public\Documents\SQL Anywhere 17\Samples\demo.db"

(24 Feb '21, 06:52) Baron

From your comments, it looks like you are using a 32-bit version of Python (which seems odd in this age of 64-bit processors) but, in any case, is C:\Program Files (x86)\SQL Anywhere 17\BIN32 in your PATH? And if you are really running a 64-bit Python, then you will need the dbcapi.dll that is in the bin64 folder (hence this needs to be in your path).

permanent link

answered 06 Oct '20, 10:40

JBSchueler's gravatar image

JBSchueler
3.3k41564
accept rate: 19%

converted 06 Oct '20, 11:48

Volker%20Barth's gravatar image

Volker Barth
40.1k361549819

I had 64-bit version of Python, then uninstalled it and installed the 32-bit version of Python, and I get always the same problem.

Now it works with the help of PYODBC

(06 Oct '20, 11:24) Baron
Comment Text Removed
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×21

question asked: 05 Oct '20, 14:31

question was seen: 3,840 times

last updated: 24 Feb '21, 06:52