OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

SQL Connection in my FastApi code is intermittent

  • Thread starter Thread starter Lucas Williamson
  • Start date Start date
L

Lucas Williamson

Guest
I have created a Fast API application for my job. This is hosted on a windows server. It's wrapped as a windows service using pyWin32 and runs a FastAPI app using Uvicorn. This works. We have a snippet of code to connect to our MS server SQL DB, we do this using the Pyodbc library.

The connection works, establishing a tcp conneciton to the server every time but occasionally the query times out and no data is transferred. This seems to happen randomly after a period of time or when a large volume of rest calls happen quickly. I've tried increasing the time out parameter and done error handling so no tcp connections stay open. Does anyone have any advice.

The connection code is very straight forward, we use windows authentication and specify the driver, server, database, timeout and trusted connections parameters. We then create the cursor, execute the query, commit it then close everything in a Finally statement.

Specific error message: errors inserting records into DB 08001 the wait operation timed out, Login timeout expired (0). A network-specific or instance-specific error has occured while establishing a connection to SQL Server. Server is not found or not accessible...

Tried increasing the timeout. Tried implementing better error handling and enforcing connections are closed.
<p>I have created a Fast API application for my job. This is hosted on a windows server. It's wrapped as a windows service using pyWin32 and runs a FastAPI app using Uvicorn. This works. We have a snippet of code to connect to our MS server SQL DB, we do this using the Pyodbc library.</p>
<p>The connection works, establishing a tcp conneciton to the server every time but occasionally the query times out and no data is transferred. This seems to happen randomly after a period of time or when a large volume of rest calls happen quickly. I've tried increasing the time out parameter and done error handling so no tcp connections stay open. Does anyone have any advice.</p>
<p>The connection code is very straight forward, we use windows authentication and specify the driver, server, database, timeout and trusted connections parameters. We then create the cursor, execute the query, commit it then close everything in a Finally statement.</p>
<p>Specific error message: errors inserting records into DB 08001 the wait operation timed out, Login timeout expired (0). A network-specific or instance-specific error has occured while establishing a connection to SQL Server. Server is not found or not accessible...</p>
<p>Tried increasing the timeout.
Tried implementing better error handling and enforcing connections are closed.</p>
 

Latest posts

Top