Pyodbc creator function ignored in create_engine (mssql)

1,168 views
Skip to first unread message

Peter Lai

unread,
May 22, 2020, 6:29:48 AM5/22/20
to sqlalchemy
example:

import pyodbc

from sqlalchemy import create_engine

def creator():
    config
= {
       
'driver': 'ODBC Driver 13 for SQL Server',
       
'host': 'localhost',
       
'port': 1433,
       
'user': 'me',
       
'pw': 'mypw',
       
'dbname': 'mydb'
   
}
   
   
return pyodbc.connect(
       
"DRIVER={{{driver}}};SERVER={host},{port};DATABASE={dbname};UID={user};PWD={pw}".format(
            driver
=config['driver'],
            host
=config['host'],
            port
=config.get('port',1433),
            dbname
=config['dbname'],
            user
=config['user'],
            pw
=config['pw']
       
)
   
)

# works
odbc_conn
= creator()

# fails
e
= create_engine('mssql://', creator=creator)




/usr/lib/python3.6/site-packages/sqlalchemy/connectors/pyodbc.py:79: SAWarning: No driver name specified; this is expected by PyODBC when using DSN-less connections
  "No driver name specified; "


This is on SqlAlchemy 1.3.17


Mike Bayer

unread,
May 22, 2020, 1:08:57 PM5/22/20
to noreply-spamdigest via sqlalchemy
that's only a warning, it's not a failure.

We will look into the warning message, however if you e.connect(), it works fine.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages