valhuber / sqlsvr-m1

test pyodbc + source venv/bin/activate on M1 for SqlSvr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Objective - Reference Example for Mac M1, SqlServer, Python

It appears there has been a good deal of struggle to get this working. This project provides the smallest possible sample - a reference implementation.

 

Background

I have:

  • an M1 Mac
  • Python 3.10.6 (via Python.org)
  • Running a SqlServer database under Docker, created from mcr.microsoft.com/mssql/server:
docker run --name sqlsvr-container --net dev-network -p 1433:1433 -d apilogicserver/sqlsvr-m1:version1.0.2

I am able to configure and connect with Azure Data Studio:

While Azure Data Studio did not require it, I also configured the database for remote access:

EXEC sp_configure 'remote access', 1;
RECONFIGURE

 

"Standard" Procedure for SQLAlchemy - worked

I have installed the ODBC driver (per this doc), like this:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18

I then created a venv in the standard manner:

python3 -m pip install -r requirements.txt

 

The Run SQLAlchemy launch successfully opens the database and discovers tables:

The issue is logged here.

 

Basic ODBC - worked

Also tried a non-SQLAlchemy connection, per Gord Thompson suggestion (thankyou!).

Appears to run:

 

Appendix: "Ed King" ODBC Driver procedure

I also attempted, without luck, the procedure below...

 

 

Using this article (many thanks!!), we used this procedure:

1. Download pyodbc-4.0.32.tar.gz into project/pyodbc

I obtained this from PyPi:

I had to unpack it (perhaps due to unfamiliarity with tar files):

2. Brew install unixodbc and rebuild pyodbc

Execute this procedure as shown in the screen shot above:

cd pyodbc
sh rebuild-pyodbc.sh

Observe Unixodbc is here:

Opens DB, but no tables, reflect fails

run.py does open the database, but no tables and reflect fails:

About

test pyodbc + source venv/bin/activate on M1 for SqlSvr


Languages

Language:Python 64.7%Language:C++ 31.7%Language:C 3.5%Language:Shell 0.0%