-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 (10054) (SQLDriverConnect)') #610
Comments
Just to rule out pyodbc itself, can you try to connect directly using the ODBC driver? Also it may be useful to look at ODBC traces from the successful Windows connection and the failed connection. (ODBC tracing Linux: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/data-access-tracing-with-the-odbc-driver-on-linux?view=sql-server-2017, Windows: https://docs.oracle.com/cd/E17952_01/connector-odbc-en/connector-odbc-configuration-trace-windows.html) |
Hi v-makouz, The isql command returns the same error -- [08001][Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 I also did the tracing for both the successful windows 10 connection and the failed linux one. I attached those logs to this message (and removed the private connection information). I looked them over but didn't see anything stick out but it's my first time ever reading those type of logs. Since we've ruled out that it is not pyodbc related I understand if you have to close the ticket. But if you or anyone else can point me in the right direction I would greatly appreciate it. Thank you, database_connection_trace_linux.txt |
Does it make any difference if you explicitly specify |
What version of OpenSSL are you using on the RedHat machine? You can run Could you do a packet capture with Wireshark in both the working and non-working cases? The difference could be due to TLS configuration. |
Adding "Encrypt=no" to the connection string still returns the same error. OpenSSL version is OpenSSL 1.0.2k-fips on the Red Hat machine. I will work on setting up wireshark to analyze both cases. Thank you both. |
@sponaugle Did you ever find a solution? I'm having the same issue. |
@adamtabrams could you provide your environment details, and Wireshark if possible? |
Environment
Issue |
You may be seeing the effect of the OpenSSL changes in Debian: https://wiki.debian.org/ContinuousIntegration/TriagingTips/openssl-1.1.1 Also note that you can get the unixODBC 2.3.7 packages here too: https://packages.microsoft.com/debian/10/prod/pool/main/u/unixodbc/ |
Hi,
|
Confirmed this worked for me: System Info |
My openssl.cnf file in Red Hat 7 does not have any existing MinProtocol or CipherString options. Also its path is at /etc/pki/tls. Not sure if that matters. |
@sponaugle I can confirm that @roirodriguez 's solution works. It seems that there are different ways to input default values. Deleting them (or not having them) it one of them. At least on Ubuntu 18.04 it works with no entries and openssl v1.1.1g A third option is mentioned in the Debian release issues, which is just a different take on the info already provided by @v-chojas. Thanks a million to all of you for pointing me in the right direction :) For future reference for conda users. My problem arose when upgrading miniconda bases image from 4.5.12 (Debian 9) to 4.7.12 (Debian 10), which was required due to some package resolving issues in existing environments. |
I can also confirm @roirodriguez worked in Debian 10 |
Just wanted to chime in here and mention that at least in my case, the issue wasn't due to SQL Server lacking support for TLSv1.2 but rather to the server's certificate having too weak a key. The ideal solution in this case is obviously to update the server certificate, but failing that it also works to set |
In case anyone (like me) stumbles onto this thread without knowing even the basics of linux; this is how I ended up implementing @roirodriguez's fix in my Dockerfile: RUN chmod +rwx /etc/ssl/openssl.cnf
RUN sed -i 's/TLSv1.2/TLSv1/g' /etc/ssl/openssl.cnf
RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf
|
Even with 'encrypt=no' I see a TDS7 pre-login message - TLS exchange sent by the client, followed by a FIN, ACK from the server. Setting CipherString = DEFAULT@SECLEVEL=1 in openssl.cnf allows the connection to proceed, there's further TDS7 pre-login messages showing the default self-signed certificate and a TLS exchange which appears to contain the login. So a) the default certificate is too weak and b) something's attempting TLS even with encrypt=no. |
See the TDS spec Encryption section: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/60f56408-0188-4cd5-8b90-25c6f2423868 The default cert (and the TLS handshake) is present to provide some protection from passive attackers, if you need something stronger you can set up your own certificate: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-encrypted-connections-to-the-database-engine |
The same error occurred when trying to connect from python using SQLAlchemy on windows. |
This is a TLS configuration issue, and is unrelated to pyODBC. |
Well can you document it somewhere then? Because clearly lots of people hit the problem. Ideally with the error messages so it's good Google bait. Also that |
The behaviour of TDS Encryption is documented in the link I posted above. |
Clearly nobody knows how to find those documents or that they're the root cause of their connection problems since people keep filing bugs. Perhaps on https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Linux or https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-ver15 or https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/known-issues-in-this-version-of-the-driver?view=sql-server-ver15 ? |
after adding to /etc/ssl/openssl.cnf the lines MinProtocol = TLSv1.0 and CipherString = DEFAULT@SECLEVEL=1 |
You will need to provide a lot more information about your environment for anyone else to be able to give you more assistance. |
my environment is Ubuntu 20.04 LTS, running nginx web service and PHP 7.4. from there I try to connect to M$ SQL Server 2014 database on a Windows 2012 R2 server. |
Everything in that list supports TLS 1.2. Make sure your server has this update: |
Still running into this issue even after changing TLS configuration on Debian 10. My connection string is the following: If I change the connection string to |
I had the same issue:
And it was solved adding Encrypt=no
|
Boa noite! Tive o mesmo problema e resolvi com o Encrypt=no OperationalError: ('08001', '[08001] fe_sendauth: no password supplied\n (101) (SQLDriverConnect)') Solução: import pyodbc dados_conexao = ("Driver={PostgreSQL ODBC Driver(UNICODE)};" conexao = pyodbc.connect(dados_conexao) |
En windows 11, me faltaba instalar openpyxl, pip install openpyxl. |
Client environment
IssueI'm trying to connect to a remote SQL server hosted on a Windows Machine with SQL Server 2012. I want to read a table in the SQL database. The pyodbc connection command was the following:
I got a connection error:
I tried to connect to the remote server using telnet on the 1433 port and it is ok. Then, I checked the SQL connection using the I had to change the OpenSSL config following the issue comment to be able to connect at least with The OpenSSL version is the following I also tried to add How can that error be solved? |
You can |
Thanks for your support @v-chojas Here the last part of the |
If you actually post the files rather than images that can't be searched, then I may be able to read them. |
Hi. The problem has been solved and the files are no longer available. |
@gruossomonica hi! Im having the same issue. I can connect using the isql but not with pyodbc. It'll be so helpfull if you could tell me more about how you fix your problems! Thanks a lot! |
Hi @jose-cheble, there were some problems with the sql server account. I have no useful tips. The IT department solved the issue. |
@v-chojas Hi! I'm running a Docker container with Debian 11 and using a Flask app. I can connect using |
10054 - connection reset by peer. Are you sure connection string is identical in success and failure case? |
@v-chojas not only is the same connection string (i've checked it several times) but if a run my module where the connection to the sql server is made, the connection is succsessfull (python3 conn_sql_server.py). this is conn_sql_server.py
but imported from another module (its an endpoint in flask) it throws the 10054.
|
Im having the same issue.@jose-cheble,Just like you! |
@mybugubird yesterday I solved it. For my case the issue was that my flask application also was using mysql-connector-python. Its seems that when the mysql library is imported some dependencies are in conflict. Also would be a good idea check the working directory, It dependes from where you execute the app. |
MSSQL Server typically uses TLS/SSL for secure communication. By default, MSSQL Server typically supports multiple TLS versions, including TLS 1.0. However, due to security considerations, newer OpenSSL versions may not default to TLS 1.0 as it is considered insecure. By setting MinProtocol to TLSv1.0, you explicitly told OpenSSL that TLS 1.0 is allowed, which may solve some connection issues, especially if MSSQL Server still requires TLS 1.0 for communication. sudo vim /etc/ssl/openssl.cnf MinProtocol = TLSv1.0 |
@sponaugle @eljirg I am facing the same problem. In Red Hat (in my case amazon Linux), you must configure /etc/pki/tls/openssl.cnf. First, add or change,
and add to last line
I write a bash code doing this job.
|
I can confirm that this works on Amazon Linux 2023, thanks @triplehoon. |
Works for me on In /etc/ssl/openssl.cnf file : 1/ change 2/ add those lines at the end of file
Then test it with
|
Hello, I am getting the similar errors as mentioned above, but my case is a bit different. All my other processes/functions using a single process/cpu when trying to connect to sql server are working fine but when I use multiprocessing(even with 1cpu) of python it fails with the below errors. pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 (10054) (SQLExecDirectW)') pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure (-2147467259) (SQLEndTran)')
I am seeing this only when I am using multiprocessing on a linux system. I have other processes from same environment to the same sqlserver that doesn't use multiprocessing which don't fail. The weird part is, if I try to run this from my local windows machine with 8cpu with same code and same sql server, it worked every time without any issues. I tried increasing IOPS on sql server but no luck. I would really appreciate any guidance to handle this error. EDIT : I am also using pandas==2.2.2 to connect to sql server with pd.read_sql with pyodbc connection. I am not using sql alchemy due to some other package version conflicts. |
@pmandadkes1207 ODBC connections don't like being forked in a different process. lurcher/unixODBC#149 |
Thank you @v-chojas. As per the conversation in the link there are few approaches suggested. What would be the best way to handle this ? As one user suggested should I use the below :
In my case I should definitely use parallel processing due to the amount of data I have to process. Again this is only happening on Linux instance as I mentioned above. Would setting start method to spawn be a better option or do you have any other recommendation ? I really appreciate your help. |
You can try that and see whether it works for you. The goal is to not have the ODBC connections inherited across forked processes. |
@v-chojas Setting start method to 'spawn' resolved the issue. Thank you for pointing me to the source of the issue. |
This was truly the solution and thank you 🎉 Just dropping this out here, Hoping to save someone a compelling amount of time, If they are faced with the same challenge 🙏🏼 |
I've managed to get the connection working with ssl to an aws rds instance by using the following Variables for database name etc removed. Path to the SSL certificate included in the Lambda layerssl_certificate_path = './us-east-2-bundle.pem' Connection string with SSL encryptionconnection_string = ( try:
except pyodbc.Error as e: finally: No dsn connection just trying to see if I can connect. odbcinst.ini [ODBC] |
From where are you seeing that "SSL_Certificate" is a valid connection string keyword? Because it's not. |
@v-chojas your right it's not part of the dsn - SSL_CERT_FILE is an environment variable https://stackoverflow.com/questions/14286265/how-to-use-ssl-cert-file-for-openssl-windows-openssl-1-0-1c |
Environment
Hi, I am running the following --
and am trying to access a SQL SERVER (version 10.0.1600.22) hosted on a Windows NT 5.2 (XP/Server 2003) machine.
Code
`def connectToSQLServer(server_name, username, password, db_name):
conn = connectToSQLServer(server_name='<server_name>', username='',password=,db_name='<db_name>')`
Issue
Issue
I am receiving the following error --
'Driver={ODBC Driver 17 for SQL Server};'
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746 (10054) (SQLDriverConnect)')
I am able to access several other SQL Server machines using the same environment and code without issue, although they are using more recent Operating Systems (Windows NT 6.0+) and SQL Server versions (10.5+).
I understand that Windows NT 5.2 and SQL Server (10.0.1600.22) are very old and no longer supported. I read the following ticket (microsoft/msphpsql#252) and some people suggested the Operating System needs to be upgraded. So I'm wondering if that may be the case here.
However, I am a little skeptical because I am able to establish connection when I run the same code but from my local Windows 10 laptop, which uses the Windows equivalent of the same ODBC driver. My local Windows 10 machine also uses the same Python and pyodbc versions. So my real question is, how come I can establish a connection from my Windows 10 machine but not from the Linux machine? Could there be something else at play here?
Thanks a lot for your help.
The text was updated successfully, but these errors were encountered: