Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import pyodbc
|
|
| 4 |
# Fixed SQL Server details
|
| 5 |
SERVER = "indsr-foundry.database.windows.net"
|
| 6 |
DATABASE = "foundry_db_monarch"
|
|
|
|
| 7 |
|
| 8 |
st.set_page_config(page_title="SQL Server Connection Test", layout="centered")
|
| 9 |
|
|
@@ -17,7 +18,7 @@ def test_connection(username, password):
|
|
| 17 |
"""Attempts to connect to the SQL Server and returns success or failure message."""
|
| 18 |
try:
|
| 19 |
conn_str = (
|
| 20 |
-
f"DRIVER={{
|
| 21 |
f"SERVER={SERVER};"
|
| 22 |
f"DATABASE={DATABASE};"
|
| 23 |
f"UID={username};"
|
|
@@ -25,9 +26,9 @@ def test_connection(username, password):
|
|
| 25 |
)
|
| 26 |
conn = pyodbc.connect(conn_str, timeout=5)
|
| 27 |
conn.close()
|
| 28 |
-
return "Connection successful! You are connected to SQL Server."
|
| 29 |
except Exception as e:
|
| 30 |
-
return f"Connection failed: {str(e)}"
|
| 31 |
|
| 32 |
# Button to test connection
|
| 33 |
if st.button("Test Connection"):
|
|
@@ -35,5 +36,4 @@ if st.button("Test Connection"):
|
|
| 35 |
result = test_connection(username, password)
|
| 36 |
st.write(result)
|
| 37 |
else:
|
| 38 |
-
st.write("Please enter both username and password.")
|
| 39 |
-
|
|
|
|
| 4 |
# Fixed SQL Server details
|
| 5 |
SERVER = "indsr-foundry.database.windows.net"
|
| 6 |
DATABASE = "foundry_db_monarch"
|
| 7 |
+
DRIVER = "ODBC Driver 17 for SQL Server" # Use the correct driver name
|
| 8 |
|
| 9 |
st.set_page_config(page_title="SQL Server Connection Test", layout="centered")
|
| 10 |
|
|
|
|
| 18 |
"""Attempts to connect to the SQL Server and returns success or failure message."""
|
| 19 |
try:
|
| 20 |
conn_str = (
|
| 21 |
+
f"DRIVER={{{DRIVER}}};"
|
| 22 |
f"SERVER={SERVER};"
|
| 23 |
f"DATABASE={DATABASE};"
|
| 24 |
f"UID={username};"
|
|
|
|
| 26 |
)
|
| 27 |
conn = pyodbc.connect(conn_str, timeout=5)
|
| 28 |
conn.close()
|
| 29 |
+
return "✅ Connection successful! You are connected to SQL Server."
|
| 30 |
except Exception as e:
|
| 31 |
+
return f"❌ Connection failed: {str(e)}"
|
| 32 |
|
| 33 |
# Button to test connection
|
| 34 |
if st.button("Test Connection"):
|
|
|
|
| 36 |
result = test_connection(username, password)
|
| 37 |
st.write(result)
|
| 38 |
else:
|
| 39 |
+
st.write("⚠️ Please enter both username and password.")
|
|
|