Skip to content

[ODBC Driver 13 for SQL Server][SQL Server]'SYSDATETIME' is not a recognized built-in function name #21

@denisbabaev

Description

@denisbabaev

Environment

OS: Windows 2003 (NT 5.2) SP1 3790
DB: Microsoft SQL Server Standard 2005 x86

Python: 3.7.5 x64
pyodbc: 4.0.27
django-mssql-backend: 2.3.0
OS: Windows 10 x64
DB: MS SQL
driver: ODBC Driver 13 for SQL Server

Issue

I'm trying to connect to the database with following settings_dict:

        {'ENGINE': 'sql_server.pyodbc', 'HOST': '10.11.241.16', 'PORT': 1433, 'USER': 'rsafeadmin', 'PASSWORD': 'Qwerty123', 'OPTIONS': {'driver': 'ODBC Driver 13 for SQL Server'}, 'TIME_ZONE': 'America/Chicago', 'CONN_MAX_AGE': 0, 'AUTOCOMMIT': True, 'NAME': 'master'}

Expected behavior:
Successfull connection
Observed behavior:
[ODBC Driver 13 for SQL Server][SQL Server]'SYSDATETIME' is not a recognized built-in function name. (195) (SQLExecDirectW)

SQL Server 2005 has no function SYSDATETIME. It has GETDATE instead. So to manage this issue i had to change base.py (line 356):

        val = cursor.execute('SELECT SYSDATETIME()').fetchone()[0]

I simply replaced with:

        try:
            val = cursor.execute('SELECT SYSDATETIME()').fetchone()[0]
        except Exception:
            # unable to find SYSDATETIME command, invoke GETDATE
            val = cursor.execute('SELECT GETDATE()').fetchone()[0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions