Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pyodbc connect to sql server

import pyodbc 
# Some other example server values are
# server = 'localhostsqlexpress' # for a named instance
# server = 'myserver,port' # to specify an alternate port
server = 'tcp:myserver.database.windows.net' 
database = 'mydb' 
username = 'myusername' 
password = 'mypassword' 
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
Comment

pyodbc connect

import pyodbc 

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=server_name;'
                      'Database=database_name;'
                      'Trusted_Connection=yes;')

cursor = conn.cursor()
cursor.execute('SELECT * FROM table_name')

for i in cursor:
    print(i)
Comment

connect with pyodbc with statement

with pyodbc.connect(conx_string) as conx:
    cursor = conx.cursor()
    cursor.execute(query)
    data = cursor.fetchall()    
Comment

PREVIOUS NEXT
Code Example
Python :: convert a data frame column values to list 
Python :: remove empty lines from file python 
Python :: how to run django tests 
Python :: python day of the week 
Python :: renaming multiple columns in pandas 
Python :: df empty 
Python :: python largest value in list 
Python :: how to remove the last item in a list python 
Python :: python filter list of strings 
Python :: tkinter keep window in front 
Python :: aiohttp get 
Python :: python remove new line 
Python :: time now random seed python 
Python :: remove particular row number in pandas 
Python :: OneHotEncoder(categorical_features= 
Python :: python find closest lower value in list 
Python :: Django Check hashed Password 
Python :: python undefine variable 
Python :: how to plot corilation python 
Python :: swap list items in python 
Python :: python print utf-8 
Python :: python [remote rejected] master - master (pre-receive hook declined) 
Python :: save and load a machine learning model using Pickle 
Python :: open file python 
Python :: python rgb colors 
Python :: jupyter notebook add color text 
Python :: pandas convert series of datetime to date 
Python :: python date from string 
Python :: how to search a file in windows 10 using python 
Python :: python fibonacci 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =