Problem to connect to sql server database from MacBook

Hi all,
there is my problem:

  1. I have Macbook with M2 chip => on it I have started programming with python
  2. Second is a windows laptop, where I have a sql server => database
  3. I tried to use pyodbc to connect to this database … m2 chip => I had to install homebrew and brew unixodbc … etc
  4. I have finally this code to connect …
drivers = pyodbc.drivers()
for d in drivers:
    print(d)
conn = pyodbc.connect('DRIVER={ODBC Driver 18 for SQL Server}; \
                    Server=SERVER-NAME; \
                    Database=DTB-NME; \
                    User ID=USERNAME; \
                    Password=PASS')

cursor = conn.cursor()
cursor.execute('SELECT name FROM cars')
for i in cursor:
    print(i)

AND … this ERROR :

pyodbc.OperationalError: ('HYT00', '[HYT00] 
[Microsoft][ODBC Driver 18 for SQL Server]
Login timeout expired (0) (SQLDriverConnect)')

Can you help me ? … I have MacBook and work in python only few days … thanks a lot, indeed !!!

It works now … I don’t know why, but I think it is because I changed

User ID => UID
Password => PWD
ODBC Driver 18 => ODBC Driver 17
+ Trusted_Connection=no;

so this is done.

It’s good that you’ve solved this for yourself and it’s also good that you’ve taken the time to post back and say as much. Now, anyone else with the same issue may find your thread of help to them.

If you do figure out the issue, maybe you’ll update this so that it will be of even more help to others.

One more important info … I realised that half of problem was with sql server … wrong setting …for example maybe … enable TCP/IP … etc

Hi Sanada,

I’m encountering the same issue. Can you elaborate on how you fixed the issue? Thanks in advance!

Kind regards,

Nigel