Skip to content

Instantly share code, notes, and snippets.

@parzibyte

parzibyte/bd.py Secret

Created June 14, 2019 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/a72bfa843429419fd3ac1875a31d2ebe to your computer and use it in GitHub Desktop.
Save parzibyte/a72bfa843429419fd3ac1875a31d2ebe to your computer and use it in GitHub Desktop.
"""
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