python is very famous Interpreted language.
It supports a verity of databases. here web healer is going to share they how to connect MS SQL Server database in python.
code to connect MS SQL server database in python
import pyodbc
# Trusted Connection to Named Instance
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.\SQL2K19;DATABASE=SampleDB;Trusted_Connection=yes;')
cursor=connection.cursor()
cursor.execute("SELECT @@VERSION as version")
while 1:
row = cursor.fetchone()
if not row:
break
print(row.version)
cursor.close()
connection.close()
No comments:
Post a Comment