File size: 1,297 Bytes
484fe03
cd20fb8
484fe03
6438c5f
 
 
484fe03
6438c5f
484fe03
6438c5f
484fe03
6438c5f
 
 
484fe03
6438c5f
cd20fb8
484fe03
cd20fb8
 
 
 
 
 
9ae496e
cd20fb8
484fe03
9ae496e
6438c5f
 
 
 
 
 
 
9ae496e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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.")