Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

SQL Server Connection issues with Flask Web App

$
0
0

I have a python flask webapp and when the page is loading, connects to our SQL Server DB and saves certain tables as Panda data frames. This operation must happen as the page is loaded in. I am having issues connecting to my Server and database. Locally, everything runs completely fine, so I know this is a server-side issue. We have VNet integration set up for the web application and are experiencing weird and inconsistent errors.

The connection string that we are using is the following for SQLAlchemy:

    user = os.environ["USER_NAME"]    password = os.environ["PASSWORD"]    hostName = os.environ["HOSTNAME"]    port = os.environ["SQLPORT"]    db = os.environ["DATABASE"]    # Establishing the database connection URI    database_uri = f"mssql+pyodbc://{user}:{password}@{hostName}:{port}/{db}?driver=ODBC+Driver+17+for+SQL+Server"    engine = create_engine(database_uri)

We learnt recently that the hostname was causing us issues. What I was using locally was not working in the web app (shortened name for the host). We attempted two possible solutions. One was the numerical address which did not work, and the other was the full name.

The full name for the host name worked when I restarted the web app. However, it is no longer working.

This morning, I received the same SQL Server connection error which is:sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

I then tried to switch the host name back to numerical address and it still was not working. When I switched it back to the full name and restarted the application it worked, and I was able to communicate for a couple messages before an error in my code (something related to state management which is not implemented yet as this app is in testing, and we only have one instance of it). However, when I reloaded the page again, I started to receive the same SQL connection errors again. I am puzzled as to why it worked twice when the host name variable was switched to the full name and the app was restarted and why in other scenarios it does not work at all. Currently the site and the host name environment variable are in the condition they were when the web app worked, only know the same error persists and I am not sure how to solve it. I can't check application logs either since the application fails to start due to the SQL Server Connection


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>