mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.92k stars 563 forks source link

[Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) (SQLDriverConnect)' #994

Closed altintashalitmert closed 2 years ago

altintashalitmert commented 2 years ago

Environment

Issue

Hi, when I try to connect to SQL Server, this error is thrown: '08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) (SQLDriverConnect)', i have readed this issue https://github.com/mkleehammer/pyodbc/issues/967 and move to openssl the location but still can't connect to server.

ls -l /usr/local/opt/openssl/lib :

resim

ls -l /usr/local/opt/openssl@1.1/lib :

resim
gizmo93 commented 2 years ago

I had the same problem and nothing in https://github.com/mkleehammer/pyodbc/issues/967 worked. I ended with setting this environment variable when launching my script:

DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/openssl@1.1/1.1.1l_1/lib/: $DYLD_LIBRARY_PATH

and now it works.

altintashalitmert commented 2 years ago

I had the same problem and nothing in #967 worked. I ended with setting this environment variable when launching my script:

DYLD_LIBRARY_PATH=/opt/homebrew/Cellar/openssl@1.1/1.1.1l_1/lib/: $DYLD_LIBRARY_PATH

and now it works.

how can i do it?

gizmo93 commented 2 years ago

@altintashalitmert Either set it using os.environ inside Python before you import pyodbc or set it for example in your IDE before running your code. If you are using PyCharm: https://stackoverflow.com/questions/42708389/how-to-set-environment-variables-in-pycharm

dragnblow commented 2 years ago

@v-chojas and @david-engel

image via isql

which openssl image

openssl version image

Error: image

Here is the full set of errors I m currently greeted with, please help me establish a connection. thank you! FYI - I m just getting started with these technologies :)

v-chojas commented 2 years ago

That one does not appear to be OpenSSL-related. Timeout error is usually because you are not connecting to the right server, or it's not listening, or a firewall is in the way. In any case, it is a networking issue.

dragnblow commented 2 years ago

@v-chojas this works with no errors on a windows machine :(

same code, same service accts, same hostname and db.

I use a mac (Catalina)

v-chojas commented 2 years ago

Are you able to at least ping the server from the machine you're getting the connection errors? Does the server have a firewall that is not allowing the connection?

dragnblow commented 2 years ago

I can ping the server and get the following output: image

I copied only a portion of it to hide the server name and stuff, thanks @v-chojas

dragnblow commented 2 years ago

@v-chojas and David-Engel

I get the correct error now (All I did is remove the '<>' from my connection string.

image

Thank you!

v-chojas commented 2 years ago

Now you can go to https://github.com/microsoft/homebrew-mssql-release/issues/59 to apply the workaround.

dragnblow commented 2 years ago

ln -s /usr/local/Cellar/openssl@1.1/1.1.1l /usr/local/opt/openssl

@v-chojas this you mean? Sorry!

dragnblow commented 2 years ago

@v-chojas - I tried to do the above (running the 'ln -s /usr/local/Cellar/openssl@1.1/1.1.1l /usr/local/opt/openssl'

and did 'rm /usr/local/opt/openssl'

(base) h54615@C02DG42MML85 ~  which openssl

I still get the same error: image

v-chojas commented 2 years ago

Don't mix OpenSSL versions. /usr/local/opt/openssl is the right one.

dragnblow commented 2 years ago

Okay @v-chojas . sorry about the confusion, I still get the same library not loaded error :(

dragnblow commented 2 years ago

@v-chojas - Success (please find the screenshot below): image

Solution for above: image

but I get the same error using my python script: image

dragnblow commented 2 years ago

@v-chojas - I am all set, just restarted my machine and i can connect now. Thank you both (you and @David-Engel)

Solution: ln -s /usr/local/Cellar/openssl@1.1/1.1.1l/m /usr/local/opt/openssl

aravindk-ecs commented 2 years ago

@dragnblow does this if you are on linux machine we have to confirm what SSL version it's using to connect to SQL 2019 server?