Hi all, I try to connect to a SQL17 DB using the following lines in Python
I get following errors:
asked 05 Oct '20, 14:31 Baron |
"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! answered 10 Oct '20, 19:31 PaulSlater Volker Barth Thank you very much for the answer. It worked on my machine without DSN and even without service:
(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). answered 06 Oct '20, 10:40 JBSchueler Volker Barth 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
|
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?
Thanks for the reply, yes Google didn't help me before raising the question:
https://github.com/sqlanywhere/sqlanydb/issues/18
https://github.community/t/issue-loading-dbcapi-while-connecting-to-sqlanydb/12886
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
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?
Yes, I did the steps before.
import ctypes doesn't return any error.
I installed sqlanydb using pip install sqlanydb
@vlad does it work on your windows machine?