sqlacodegen

283 views
Skip to first unread message

Larry Martell

unread,
Nov 9, 2020, 6:44:03 PM11/9/20
to sqlalchemy
I am trying to use sqlacodegen on a mac to generate models from a MS SQL db. I get this error when I run:

sqlacodegen mssql+pyodbc:xxx

pyodbc.InterfaceError: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found and no default driver specified (0) (SQLDriverConnect)')

I can successfully connect to the db using the same DSN:

$ python3.8Python 3.8.6 (v3.8.6:db455296be, Sep 23 2020, 13:31:39) 

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> from sqlalchemy import create_engine

>>> create_engine("mssql+pyodbc://xxx")

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sqlalchemy/connectors/pyodbc.py:80: SAWarning: No driver name specified; this is expected by PyODBC when using DSN-less connections

  util.warn(

Engine(mssql+pyodbc://xxx)

>>> 

Mike Bayer

unread,
Nov 9, 2020, 11:03:03 PM11/9/20
to noreply-spamdigest via sqlalchemy
this has to do with how you are formatting your URL, and it is being seen as a hostname and not a DSN name.  can't provide any more help without seeing how you are formatting this URL as well as what is the actual method you are trying to use to connect (DSN or hostname).
--
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.

Larry Martell

unread,
Nov 9, 2020, 11:22:45 PM11/9/20
to sqlalchemy

sqlacodegen mssql+pyodbc://user:password@host/database

Mike Bayer

unread,
Nov 10, 2020, 8:42:51 AM11/10/20
to noreply-spamdigest via sqlalchemy
that's a hostname connection so it requires that you also include the driver name in the URL.  follow the example at https://docs.sqlalchemy.org/en/14/dialects/mssql.html#hostname-connections .  

more background on connecting with pyodbc at https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Linux .  if you can get pyodbc to connect directly we can show you the correct URL format.

Larry Martell

unread,
Nov 12, 2020, 6:36:26 PM11/12/20
to sqlal...@googlegroups.com
That worked, thanks!
Reply all
Reply to author
Forward
0 new messages