MS SQL access from Mac

  • I am trying to access a local MS SQL server (running in a Docker container) on my Mac. I have no trouble if I use sqlcmd but I cannot get Python to work.

    Here is the beginning of a script:

    from sqlalchemy import *

    engine = create_engine('mssql+pyodbc://userid:password@localhost')
    con = engine.connect()

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

    I am new to MS SQL (have used MySQL with no problem from Python).

    Can anyone help me?

    • This topic was modified 4 years, 2 months ago by  ihf.
  • Looks like the connection string isn't complete. Here's a blog post that might help.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • What I need is step by step on setting up the driver and DSN on the Mac. I have tried countless ways with no success. Only MS SQL Server Management Studio (Windows) and Sqlcmd (on Mac) are able to talk to the Server.

  • Have you tried Azure Data Studio? I use that with containers all the time. It should work. You may have to use the IP address instead of just relying on the (localhost) getting picked up.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • I'm not sure how, but I got it working from Python. Now I would also like to get it to work from R.

    con<-dbConnect(odbc(), Driver="SQLServer", Server="localhost",Database="dbname",UID="sa",PWD="pswd",Port=1433)

    results in:

    Error: nanodbc/nanodbc.cpp:950: 01000: [unixODBC][Driver Manager]Can't open lib 'SQLServer' : file not found

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply