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 2 years, 6 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 RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • 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 RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • 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 5 (of 5 total)

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