-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
26 lines (20 loc) · 733 Bytes
/
db.py
File metadata and controls
26 lines (20 loc) · 733 Bytes
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
"""Database helper utilities.
This module provides a small helper to obtain a connection to the
local SQL Server database used by the application.
"""
import pyodbc
def get_connection():
"""Return a new pyodbc connection to the Bank database.
The function creates and returns a live connection object. Callers
are responsible for closing the connection when finished.
Returns:
pyodbc.Connection: active DB connection to the `Bank` database.
"""
# Use ODBC Driver 17 for SQL Server with Windows authentication
conn = pyodbc.connect(
"DRIVER={ODBC Driver 17 for SQL Server};"
"SERVER=localhost;"
"DATABASE=Bank;"
"Trusted_Connection=yes;"
)
return conn