Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
|
| 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 |
|
|
@@ -15,18 +14,16 @@ username = st.text_input("Database Username", placeholder="Enter your username")
|
|
| 15 |
password = st.text_input("Database Password", type="password", placeholder="Enter your password")
|
| 16 |
|
| 17 |
def test_connection(username, password):
|
| 18 |
-
"""Attempts to connect to the SQL Server
|
| 19 |
try:
|
| 20 |
-
conn_str =
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 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 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from sqlalchemy import create_engine, text
|
| 3 |
|
| 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 |
|
|
|
|
| 14 |
password = st.text_input("Database Password", type="password", placeholder="Enter your password")
|
| 15 |
|
| 16 |
def test_connection(username, password):
|
| 17 |
+
"""Attempts to connect to the SQL Server using SQLAlchemy + pytds."""
|
| 18 |
try:
|
| 19 |
+
conn_str = f"mssql+pytds://{username}:{password}@{SERVER}/{DATABASE}"
|
| 20 |
+
engine = create_engine(conn_str, pool_pre_ping=True)
|
| 21 |
+
|
| 22 |
+
with engine.connect() as connection:
|
| 23 |
+
result = connection.execute(text("SELECT 1"))
|
| 24 |
+
|
|
|
|
|
|
|
|
|
|
| 25 |
return "✅ Connection successful! You are connected to SQL Server."
|
| 26 |
+
|
| 27 |
except Exception as e:
|
| 28 |
return f"❌ Connection failed: {str(e)}"
|
| 29 |
|