cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't I connect to my database?

0 Kudos
729
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

Accepted Solutions (0)

Answers (2)

Answers (2)

Baron
Participant

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.

regdomaratzki
Product and Topic Expert
Product and Topic Expert

"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?

0 Kudos

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?

regdomaratzki
Product and Topic Expert
Product and Topic Expert
0 Kudos

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