Spaces:
Sleeping
Sleeping
Download app.py from mattn01/Excel_SQL_Processor: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/mattn01/Excel_SQL_Processor/resolve/75129a009ebb07a64ff70ab3f7bcfa98103b08f9/app.py
- Command line
-
hf download hf://spaces/mattn01/Excel_SQL_Processor@75129a009ebb07a64ff70ab3f7bcfa98103b08f9/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mattn01/Excel_SQL_Processor/resolve/75129a009ebb07a64ff70ab3f7bcfa98103b08f9/app.py
1.3 kB
| import streamlit as st | |
| from sqlalchemy import create_engine, text | |
| # Fixed SQL Server details | |
| SERVER = "indsr-foundry.database.windows.net" | |
| DATABASE = "foundry_db_monarch" | |
| st.set_page_config(page_title="SQL Server Connection Test", layout="centered") | |
| st.title("SQL Server Connection Test") | |
| # User inputs for authentication | |
| username = st.text_input("Database Username", placeholder="Enter your username") | |
| password = st.text_input("Database Password", type="password", placeholder="Enter your password") | |
| def test_connection(username, password): | |
| """Attempts to connect to the SQL Server using SQLAlchemy + pytds.""" | |
| try: | |
| conn_str = f"mssql+pytds://{username}:{password}@{SERVER}/{DATABASE}" | |
| engine = create_engine(conn_str, pool_pre_ping=True) | |
| with engine.connect() as connection: | |
| result = connection.execute(text("SELECT 1")) | |
| return "✅ Connection successful! You are connected to SQL Server." | |
| except Exception as e: | |
| return f"❌ Connection failed: {str(e)}" | |
| # Button to test connection | |
| if st.button("Test Connection"): | |
| if username and password: | |
| result = test_connection(username, password) | |
| st.write(result) | |
| else: | |
| st.write("⚠️ Please enter both username and password.") | |