Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,39 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
import pyodbc
|
| 4 |
-
import tempfile
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
st.title("Excel Processor for SQL Database")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
st.subheader("Database Credentials")
|
| 15 |
-
username = st.text_input("Database Username", value="", placeholder="Enter your username")
|
| 16 |
-
password = st.text_input("Database Password", value="", type="password", placeholder="Enter your password")
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
st.
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
if not username or not password:
|
| 25 |
-
return "⚠️ Error: Username and password are required!"
|
| 26 |
-
|
| 27 |
-
if file is None:
|
| 28 |
-
return "⚠️ Error: Please upload an Excel file."
|
| 29 |
-
|
| 30 |
try:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
f
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
return result_message
|
| 42 |
-
|
| 43 |
except Exception as e:
|
| 44 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Run Processing Button
|
| 47 |
-
if st.button("Process File"):
|
| 48 |
-
result = process_file(username, password, uploaded_file)
|
| 49 |
-
st.write(result)
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import pyodbc
|
|
|
|
|
|
|
| 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 |
|
| 10 |
+
st.title("SQL Server Connection Test")
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# User inputs for authentication
|
| 13 |
+
username = st.text_input("Database Username", placeholder="Enter your username")
|
| 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 and returns success or failure message."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
try:
|
| 19 |
+
conn_str = (
|
| 20 |
+
f"DRIVER={{SQL Server}};"
|
| 21 |
+
f"SERVER={SERVER};"
|
| 22 |
+
f"DATABASE={DATABASE};"
|
| 23 |
+
f"UID={username};"
|
| 24 |
+
f"PWD={password};"
|
| 25 |
+
)
|
| 26 |
+
conn = pyodbc.connect(conn_str, timeout=5)
|
| 27 |
+
conn.close()
|
| 28 |
+
return "Connection successful! You are connected to SQL Server."
|
|
|
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
+
return f"Connection failed: {str(e)}"
|
| 31 |
+
|
| 32 |
+
# Button to test connection
|
| 33 |
+
if st.button("Test Connection"):
|
| 34 |
+
if username and password:
|
| 35 |
+
result = test_connection(username, password)
|
| 36 |
+
st.write(result)
|
| 37 |
+
else:
|
| 38 |
+
st.write("Please enter both username and password.")
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|