pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

Hi. I have some issues with SQL server
My app locally run fine. But I have issue connect with database while deploy

Here is the error in manage app:
pyodbc.OperationalError: (‘HYT00’, ‘[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)’)

Here is my requirements.txt

Here is my connection string
def init_connection():
return pyodbc.connect(
“DRIVER={ODBC Driver 17 for SQL Server};SERVER=”
+ st.secrets[“server”]
+ st.secrets[“database”]
+ “;UID=”
+ st.secrets[“username”]
+ “;PWD=”
+ st.secrets[“password”]

conn = init_connection()

def run_query(query):
data = pd.read_sql(query, conn)
return data

And I already config access following this link:

Please feel free to send any information. Thanks so much. (;′⌒`)

Just some ideas:

  • try without the cache decorators
  • use IP address of the database server

Here are some threads with similar issues:

First of all, Thanks.
But sorry for dummy question but how can i find my IP address of my server?
and the thing i have to do is replace my server name to that IP address right?

The database server has a public IP address. If not, because the database only runs in your local network or on the same local computer, it won’t work with Streamlit Cloud anyway.

Hi, Thanks for the reply.
After fixing the error following by your suggestion, here is my new error encountered

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

Any ideas or suggestion?
Also, I have googled and it suggest to download the unixODBC. but it for linux, how can i do it for Windows?
Thanks in advance.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.