简体   繁体   中英

How to connect to SQL Server from Python Flask?

I have been trying to connect to SQL Server from Flask but with no luck.

I can connect to DB when i try in my Local Machine and it works perfectly fine, but when i try to connect from VM/Remote Desktop, i see the below error.

I have spent lot of time trying to figure out the issue and for solution, but no luck. I suspect something should be with firewalls or security.

Thanks in Advance for help.

conn = pyodbc.connect('Driver={SQL Server};'
        'Server=DEV001;'
        'Database=ZXCZ;'
        'user=gendb;'
        'Password=qwe123;')
OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver]
[DBNETLIB]SSL Security error (18) (SQLDriverConnect); 
[08001] [Microsoft][ODBC SQL Server Driver]
[DBNETLIB]ConnectionOpen (SECCreateCredentials()). (1); 
[08001] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute (0)')

Make sure you use the latest version of ODBC, that you can find here:

https://docs.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server

At the bottom of the page you'll also find a link to Installation document, in case you're installing in on something different than Windows.

Also, the connection string should look like

DRIVER={ODBC Driver 17 for SQL Server};SERVER=;DATABASE=;UID=;PWD=;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM