Table of Contents

  1. Create and activate the Python environment
  2. Install Python modules
  3. Install MS SQL
  4. Start coding & Run

Prerequisites

For this project, we used MS SQL, so the operating system is Windows Server 2012. I installed MS SQL Server 2012 Advanced. If your system is Windows 10 or Windows 11, install the latest version of MS SQL Express instead.

  1. Python 3.12
  2. Windows OS
  3. MS SQL Express
  4. Internet

Get started

Create and activate the Python environment

# Create the virtual environment
python -m venv c:\project\event

# Activate it
cd c:\project\event\Scripts
.\activate

# Deactivate it when finished
deactivate

Install Python modules

You can install these modules step by step, or use pip install -r requirement.txt.

Install modules step by step
pip install numpy
pip install pymssql
pip install pandas
pip install python-dotenv
pip install streamlit
pip list
Python modules install via requirement.txt
numpy
pymssql
pandas
python-dotenv
streamlit

Install MS SQL

MS SQL Download site

Microsoft® SQL Server® 2022 Express https://www.microsoft.com/en-us/download/details.aspx?id=104781

SQL Server installation guide https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server?view=sql-server-ver16&culture=en-us&country=us

MS SQL Remote https://www.itiohub.com/log/437.html


Start coding

First streamlit app

Example:

import streamlit as st

st.title("Hello, there!")
st.write("Welcome to my website")

Save it, then go back to PowerShell or run it in your VS Code. streamlit run app.py

The default port is 8501, but you can change the port if you want.

streamlit run app.py --server.port 80

More example and more tuorials

https://docs.streamlit.io/develop/tutorials

Connect to the SQL

Exmaple:

import streamlit as st
import pymssql

DB_SERVER = 'localhost'
DB_USER = 'sa'
DB_PASSWORD = 'AdamsonUniversity'
DB_NAME = 'Event_manage'

def get_connection():
    try:
        return pymssql.connect(
            server=DB_SERVER,
            user=DB_USER,
            password=DB_PASSWORD,
            database=DB_NAME,
            tds_version='7.0',
            as_dict=True,
        )
    except Exception as error:
        st.error(f"Cannot connect to database: {error}")
        return None
SQL connect issue:

TLS1.2 Error https://learn.microsoft.com/en-us/answers/questions/275585/tls-1-2-error-schannel-event-id-36874-and-36888

A149F105-5FF2-428B-8BE7-8753CC939579