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
pandas==1.5.3
Pillow==9.4.0
plotly==5.13.1
pyodbc==5.0.1
streamlit==1.28.2

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

conn = init_connection()

@st.cache_data(ttl=600)
def run_query(query):
data = pd.read_sql(query, conn)
return data

And I already config access following this link: https://knowledgebase.apexsql.com/configure-remote-access-connect-remote-sql-server-instance-apexsql-tools/

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.