microsoft / mssql-django

The Microsoft Django backend for SQL Server provides a connectivity layer for Django on SQL Server or Azure SQL DB.
Other
350 stars 115 forks source link

[FEATURE REQUEST] Support for SQL Server database mirroring #416

Open Wedge009 opened 1 month ago

Wedge009 commented 1 month ago

I'm guessing this may not be supported, given this package depends on pyodbc which (as far as I know) doesn't accommodate SQL Server's 'fail-over partner' connection parameter.

Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it

pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The target database, '<database name>', is participating in an availability group and is currently not accessible for queries. Either data movement is suspended or the availability replica is not enabled for read access. To allow read-only access to this and other databases in the availability group, enable read access to one or more secondary availability replicas in the group.  For more information, see the ALTER AVAILABILITY GROUP statement in SQL Server Books Online. (976)")

Describe the preferred solution The ability to have Django automatically connect to the database mirror in the case the primary server is marked as 'unavailable'.

Describe alternatives you've considered I attempted to use Django's multiple database handling via its database routers, but my router doesn't appear to be called no matter what I try.

I also experimented with python-tds connections and, assuming its 'fail-over partner' issue is resolved in the next release, it could be an option for connecting to SQL Server databases. It is the only Python package I'm aware of that claims to support database mirroring in SQL Server. However, its corresponding Django integration project, https://github.com/denisenkom/django-sqlserver, doesn't appear to be maintained any more.

Reference Documentations/Specifications https://learn.microsoft.com/en-au/sql/database-engine/database-mirroring/connect-clients-to-a-database-mirroring-session-sql-server

Wedge009 commented 3 weeks ago

I managed to get database routing working within Django as a work-around.