MSSQL.create_engine(database_name=None, auth=None, password=None)

Create a SQLAlchemy connectable engine.

Connect string format: ‘mssql+pyodbc://<username>:<password>@<dsn_name>

  • database_name (str or None) – name of a database, defaults to the name of the currently-connected database when database=None

  • auth (str or None) – authentication method (used for establish the connection), defaults to the current authentication method when auth=None

  • password (str or int or None) – user’s password; when password=None (default), it is required to manually type in the correct password to connect the PostgreSQL server


a SQLAlchemy connectable engine

Return type


  1. Use pyodbc (or pypyodbc):

    connect_string = 'driver={...};server=...;database=...;uid=username;pwd=...'
    conn = pyodbc.connect(connect_string)  # conn = pypyodbc.connect(connect_string)
  2. Use SQLAlchemy:

    conn_string = 'mssql+pyodbc:///?odbc_connect=%s' % quote_plus(connect_string)
    engine = sqlalchemy.create_engine(conn_string)
    conn = engine.connect()


>>> from pyhelpers.dbms import MSSQL

>>> mssql = MSSQL()
Connecting <server_name>@localhost:1433/master ... Successfully.

>>> db_engine = mssql.create_engine()

>>> db_engine.dispose()