-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
21 lines (18 loc) · 726 Bytes
/
database.py
File metadata and controls
21 lines (18 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pyodbc
class Database:
def __init__(self, server, database):
self.server = server
self.database = database
self.connection = None
def connect(self):
try:
self.connection = pyodbc.connect(f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={self.server};DATABASE={self.database};Trusted_Connection=yes;')
print('Connected to Database.')
except pyodbc.Error as e:
print(f"Error connecting to database: {e}")
def disconnect(self):
if self.connection:
self.connection.close()
print("Disconnected from the database.")
else:
print("No active database connection to disconnect from.")