Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

python - pyodbc.OperationalError:TCP Provider: Error code 0x2746 (10054) (SQLDriverConnect) running Flask application

I have a flask application, which I am trying to run on an Ubuntu 20.04 server that requires communicating with a SQL Server database. And whenever I try to run my code I get the following error -

ERROR

connection = pyodbc.connect(r'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 have referred to various solutions on other posts, but nothing seems to help. I have already tried the approach here - Click Here

Here's the python code, filename : app.py

from flask import Flask, render_template, request, redirect, make_response
import pyodbc, datetime
import pandas as pd

app = Flask(__name__)


# connect_db function is used to connect with the database for read and write purposes
def connect_db():
    connection = pyodbc.connect(r'Driver={ODBC Driver 17 for SQL Server};Server=servername;Database=databasename;Trusted_Connection=yes',autocommit=True)
    return connection


# index function calls the homepage
@app.route('/')
def index():
    con = connect_db()
    cursor = con.cursor()
    return render_template('index.html')


Additionally, I get no errors when I try to run this on windows with pyodbc drivers installed for the windows environment. How can I fix this error, please let me know if any additional information is required.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...