microsoft/mssql-django

file not found (0) (SQLDriverConnect)")

rngallen opened this issue · 2 comments

There are some features which are not supported yet. Please check the Limitations first to see if your bug is listed.

Software versions

  • Django: 5.0.3
  • mssql-django: 1.4.2
  • python: 3..12.2
  • SQL Server: 2019
  • OS: Mac Os Sonoma on M2 CHIP

Table schema and Model

Database Connection Settings
// Paste your database settings from Settings.py here. "s_db": { "ENGINE": "mssql", "NAME": config("S_DB_NAME"), "USER": config("S_DB_USER"), "PASSWORD": config("S_DB_PASSWORD"), "HOST": config("S_DB_HOST"), "PORT": "", "OPTIONS": { "driver": "ODBC Driver 17 for SQL Server", }, },

Problem description and steps to reproduce

Running custom command to load data from another projects'/apps' database

Expected behavior and actual behavior

File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 275, in ensure_connection
self.connect()
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 256, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/mssql/base.py", line 368, in get_new_connection
conn = Database.connect(connstr, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/ngallen/development/python/fuel_delivery/manage.py", line 24, in
main()
File "/Users/ngallen/development/python/fuel_delivery/manage.py", line 20, in main
execute_from_command_line(sys.argv)
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/core/management/init.py", line 442, in execute_from_command_line
utility.execute()
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/core/management/init.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/development/python/fuel_delivery/sage/management/commands/loadfromsage.py", line 107, in handle
_load_from_sage()
File "/Users/ngallen/development/python/fuel_delivery/sage/management/commands/loadfromsage.py", line 10, in _load_from_sage
with connections["sage_db"].cursor() as cursor:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 316, in cursor
return self._cursor()
^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/mssql/base.py", line 261, in _cursor
conn = super()._cursor()
^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 292, in _cursor
self.ensure_connection()
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 274, in ensure_connection
with self.wrap_database_errors:
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/utils.py", line 91, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 275, in ensure_connection
self.connect()
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/django/db/backends/base/base.py", line 256, in connect
self.connection = self.get_new_connection(conn_params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ngallen/.local/share/virtualenvs/fuel_delivery-cfjmI6lw/lib/python3.12/site-packages/mssql/base.py", line 368, in get_new_connection
conn = Database.connect(connstr, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")
(fuel_delivery-cfjmI6lw) ngallen@Ramadhans-MBP fuel_delivery %
Error message/stack trace

Any other details that can be helpful

Looks like a problem with your ODBC installation. Did you install it via these instructions?

https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15

Already fixed