on 2020 Oct 05 3:31 PM
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)
Request clarification before answering.
"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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.