Untitled
unknown
python
3 years ago
776 B
4
Indexable
#!/usr/bin/env python3 import pyodbc # Some other example server values are # server = 'localhost\sqlexpress' # for a named instance # server = 'myserver,port' # to specify an alternate port server = 'RemoteSupport,1433' database = 'DBNAME' username = 'sa' password = 'xxxxxxxxxxxxxxxx' # ENCRYPT defaults to yes starting in ODBC Driver 18. It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks. cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER='+server+';DATABASE='+database+';ENCRYPT=yes;UID='+username+';PWD='+ password+';Encrypt=no') cursor = cnxn.cursor() cursor.execute('SELECT top 10 * FROM sysobjects;') row = cursor.fetchone() while row: print(row) print('\n') row = cursor.fetchone() cnxn.close()
Editor is loading...