The issue is caused by your combination of
- pypyodbc
- the ancient ODBC driver named "SQL Server", and
- Azure SQL
When pypyodbc tries to establish the connection via pypyodbc.connect
one of the (many!) things it does is try to determine whether you have read-only or read-write access to the database. The ODBC call that it uses is translated by the "SQL Server" ODBC driver as
select substring('NY',status/1024&1+1,1) from master..sysdatabases where name=DB_NAME()
which Azure SQL apparently does not like.
By comparison, a more modern ODBC driver like "ODBC Driver 11 for SQL Server" translates that same ODBC call into
SELECT CASE DATABASEPROPERTYEX( DB_NAME(), 'Updateability') WHEN 'READ_ONLY' THEN 'Y' ELSE 'N' END
which may be more palatable to Azure SQL.
So, you can either switch to a newer ODBC driver, or you can try using pyodbc instead of pypyodbc since pyodbc does not seem to query the RO/RW status of the database when it connects.