3

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.

heisenbug29
  • 123
  • 1
  • 10
  • I see that you are trying to use `Trusted_Connection=yes`. Do you have Kerberos set up in your environment? – Gord Thompson Jan 09 '21 at 12:46
  • @GordThompson No, I do not have Kerberos set up in my environment, but I am still in development, will change it once deployed. Is that the issue for my error? – heisenbug29 Jan 11 '21 at 19:17

0 Answers0