mattn01 commited on
Commit
171f70d
·
verified ·
1 Parent(s): c96259b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -4,7 +4,6 @@ from sqlalchemy import create_engine, text
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" # Make sure this matches the installed driver
8
 
9
  st.set_page_config(page_title="SQL Server Connection Test", layout="centered")
10
 
@@ -15,19 +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 using SQLAlchemy + pyodbc."""
19
  try:
20
- conn_str = (
21
- f"mssql+pyodbc://{username}:{password}@{SERVER}/{DATABASE}?"
22
- f"driver={DRIVER}&Encrypt=yes&TrustServerCertificate=no"
23
- )
24
  engine = create_engine(conn_str, pool_pre_ping=True)
25
-
26
  with engine.connect() as connection:
27
  result = connection.execute(text("SELECT 1"))
28
-
29
  return "✅ Connection successful! You are connected to SQL Server."
30
-
31
  except Exception as e:
32
  return f"❌ Connection failed: {str(e)}"
33
 
 
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 + pymssql (no ODBC)."""
18
  try:
19
+ conn_str = f"mssql+pymssql://{username}:{password}@{SERVER}:1433/{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