Created
March 11, 2022 05:19
-
-
Save benyaminl/eccf04ce5cb71eb3a25a6587b7781a5b to your computer and use it in GitHub Desktop.
Python ODBC connect to SQL Server 2008 from Windows 10 21H2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyodbc | |
# Specifying the ODBC driver, server name, database, etc. directly | |
con = pyodbc.connect('DRIVER={SQL Server Native Client 10.0};SERVER=127.0.0.1;PORT=1433;DATABASE=coba;UID=sa;PWD=12345') | |
# Using a DSN, but providing a password as well | |
# cnxn = pyodbc.connect('DSN=test;PWD=password') | |
# Create a cursor from the connection | |
db = con.cursor() | |
db.execute("SELECT @@version;") | |
row = db.fetchone() | |
while row: | |
print(row[0]) | |
row = db.fetchone() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment