Skip to content

Instantly share code, notes, and snippets.

@gokaybiz
Created Dec 26, 2020
Embed
What would you like to do?
Example python mssql client
#https://datatofish.com/how-to-connect-python-to-sql-server-using-pyodbc/
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=server_name;'
'Database=database_name;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
cursor.execute('SELECT * FROM database_name.table')
for row in cursor:
print(row)
import pandas as pd
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=RON\SQLEXPRESS;'
'Database=TestDB;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
sql_query = pd.read_sql_query('SELECT * FROM TestDB.dbo.Person',conn)
print(sql_query)
print(type(sql_query))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment