Ejemplo: conectarse al servidor sql con python
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()
#Sample select query
cursor.execute("SELECT @@version;")
row = cursor.fetchone()
while row:
print(row[0])
row = cursor.fetchone()
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)