import streamlit as st import pyodbc # Fixed SQL Server details SERVER = "indsr-foundry.database.windows.net" DATABASE = "foundry_db_monarch" DRIVER = "ODBC Driver 17 for SQL Server" # Use the correct driver name 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 and returns success or failure message.""" try: conn_str = ( f"DRIVER={{{DRIVER}}};" f"SERVER={SERVER};" f"DATABASE={DATABASE};" f"UID={username};" f"PWD={password};" ) conn = pyodbc.connect(conn_str, timeout=5) conn.close() 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.")