Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Connect Python code to SQL Server database

$
0
0

I am playing around with Python in VS Code and I can't seem to connect my code to my SQL Server database. Any suggestions? Below is the code and the error message I get when I run the code.

Code snippet:

from http import serverfrom os import nameimport tkinter as tkfrom tkinter import ttkfrom tkinter import filedialog, Tk, Label, Buttonfrom PIL import Image, ImageTkimport tkinter.messageboximport pyodbcfrom datetime import datetime#Initialize the database connectionserver="MAURICE-PC\\CLOCKIFY"username="sa"password="clockify"database="master"connection = pyodbc.connect("DRIVER={SQL Server};SERVER='MAURICE-PC\\CLOCKIFY';DATABASE='master';UID='sa';PWD='clockify'")cursor = connection.cursor()

Error code

Traceback (most recent call last):  File "F:\Visual Studio Code Workspace\Time and Attendance\.venv\T&A.py", line 23, in <module>          connection = pyodbc.connect("DRIVER={SQL Server};SERVER='MAURICE-PC\\CLOCKIFY';DATABASE='master';UID='sa';PWD='clockify'")                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (123)')

I enabled the remote connection via SSMS, I enabled the TCP/IP protocol in SQL Server Configuration Manager and allowed the port in the firewall's incoming and outgoing connections


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>