From e9e1e99a974a3b1588d24ca6c82c402ab6e6226d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartal=20L=C3=A6arsson?= Date: Sat, 14 Feb 2026 22:51:46 +0000 Subject: [PATCH] initial commit --- README.md | 15 +++++++++++++++ connect_sql_server_exception.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 README.md create mode 100644 connect_sql_server_exception.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..2eafcb3 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# README + +## requirements + +python 3.13 or something +mssql server +install pip install pyodbc + + + +check if odbc 17 (or other version) +on windows search for odbc data sources. +go to the menu point drivers. +There should odbc driver 17 for mssql server or something like that + diff --git a/connect_sql_server_exception.py b/connect_sql_server_exception.py new file mode 100644 index 0000000..8172ada --- /dev/null +++ b/connect_sql_server_exception.py @@ -0,0 +1,22 @@ +import pyodbc + +try: + connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes') + + cursor = connection.cursor() + + print() + print("Successfully connected to SQL Server") + print() + + cursor.close() + connection.close() + +except pyodbc.Error as ex: + print() + print("exception: ", ex) + print("closing program") + print() + exit() + +print()