mattn01 commited on
Commit
6438c5f
·
verified ·
1 Parent(s): 484fe03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -39
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
- # Streamlit page setup
8
- st.set_page_config(page_title="Excel to SQL Processor", layout="centered")
 
9
 
10
- # Title
11
- st.title("Excel Processor for SQL Database")
12
 
13
- # Username and Password Input
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
- # File Upload
19
- st.subheader("Upload Excel File")
20
- uploaded_file = st.file_uploader("Choose an Excel file", type=["xlsx"])
21
 
22
- # Dummy function to simulate processing
23
- def process_file(username, password, file):
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
- # Save the uploaded file temporarily
32
- temp_dir = tempfile.mkdtemp()
33
- file_path = os.path.join(temp_dir, file.name)
34
- with open(file_path, "wb") as f:
35
- f.write(file.getvalue())
36
-
37
- # Load the Excel file (dummy processing)
38
- df = pd.read_excel(file_path)
39
- result_message = f"✅ File '{file.name}' successfully uploaded and read. {len(df)} rows found."
40
-
41
- return result_message
42
-
43
  except Exception as e:
44
- return f" Error processing file: {str(e)}"
 
 
 
 
 
 
 
 
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