-
-
Save parzibyte/a72bfa843429419fd3ac1875a31d2ebe to your computer and use it in GitHub Desktop.
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
""" | |
Conexión a SQLServer con Python | |
Ejemplo de CRUD evitando inyecciones SQL | |
@author parzibyte | |
Más tutoriales en: | |
parzibyte.me/blog | |
""" | |
import pyodbc | |
direccion_servidor = '127.0.0.1' | |
nombre_bd = 'pruebas_parzibyte' | |
nombre_usuario = 'usuario' | |
password = 'hunter2' | |
try: | |
conexion = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + | |
direccion_servidor+';DATABASE='+nombre_bd+';UID='+nombre_usuario+';PWD=' + password) | |
# OK! conexión exitosa | |
except Exception as e: | |
# Atrapar error | |
print("Ocurrió un error al conectar a SQL Server: ", e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment