on 2023 Dec 13 1:11 PM
import sqlanydb params = { 'uid': 'user', 'pwd': '**********', 'eng': 'servername', 'dbn': 'databasename' } conexao = sqlanydb.connect(**params) cursor = conexao.cursor() query = 'select * from geempre' cursor.execute(query) retorno = cursor.fetchall() conexao.close() for r in retorno: print(r) error: C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\venv\\Scripts\\python.exe C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\Intranet_Obj\\conexao_dominio.py Traceback (most recent call last): File "C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\Intranet_Obj\\conexao_dominio.py", line 12, in <module> conexao = sqlanydb.connect(**params) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\venv\\Lib\\site-packages\\sqlanydb.py", line 566, in connect return Connection(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\venv\\Lib\\site-packages\\sqlanydb.py", line 633, in __init__ self.handleerror(*error) File "C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\venv\\Lib\\site-packages\\sqlanydb.py", line 644, in handleerror eh(self, None, errorclass, errorvalue, sqlcode) File "C:\\Users\\bi01\\Documents\\GitHub\\Intranet_Objetiva\\venv\\Lib\\site-packages\\sqlanydb.py", line 383, in standardErrorHandler raise errorclass(errorvalue,sqlcode) sqlanydb.OperationalError: (b'Database server not found', -100) Process finished with exit code 1
Request clarification before answering.
I am using PYODBC and this connection string works (here I should define the driver name).
import pyodbc from pyodbc import Cursor conn = pyodbc.connect('Driver={SQL Anywhere 17};Database=???;Server=???;UID=???;pwd=???') cursor = conn.cursor().execute('select * from dummy')
BTW, your example code worked also worked for me, so the problem is probably in your environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"Database server not found" means that the SQL Anywhere client was not able to find a server running called "servername" with a database mounted on the server called "databasename".
Can you describe how you started the SQL Anywhere database engine prior to trying to connect?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, the data I posted is not correct because I don't want to share sensitive company information. However, with the same data, I can log in to the database using SQL Central, so I'm sure the data is correct. I have the following drivers installed on my computer: ['SQL Server', 'UltraLite 17', 'SQL Anywhere 16', 'SQL Anywhere 17', 'ODBC Driver 17 for SQL Server', 'UltraLite 16']. However, I couldn't connect using the pyodbc library.
The database is already running, and in the engine, I entered the server name. Is that correct?
You haven't given us a lot of information to go on here. Let me try and attack this a different way. If I open up a DOS prompt the following commands work like a charm for me :
dbinit -mpl 3 -dba dba,sql databasename.db dbspawn dbsrv17 -n servername databasename.db python test.py
The contents of test.py are :
import sqlanydb params = { 'uid': 'dba', 'pwd': 'sql', 'eng': 'servername', 'dbn': 'databasename' } con = sqlanydb.connect( **params ) cur = con.cursor() cur.execute('select count(*) from sysfile') assert cur.fetchone()[0] > 0 con.close() print('Done!')
Do the commands above work for you?
If no, please describe what goes wrong.
If yes, what is different in your real environment where it doesn't work?
Reg
User | Count |
---|---|
76 | |
30 | |
8 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.