Connecting to SQL Server

34 views
Skip to first unread message

John Burke

unread,
Jul 3, 2019, 11:52:35 PM7/3/19
to Django users
Getting the following error:

  File "...\venv\lib\site-packages\sql_server\pyodbc\base.py", line 362, in init_connection_state
    val = cursor.execute('SELECT SYSDATETIME()').fetchone()[0]
ValueError: hour must be in 0..23

John Burke

unread,
Jul 3, 2019, 11:52:35 PM7/3/19
to Django users
Trying to connect to SQL Server from Django

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'dbname',
        'HOST': 'hostname',
        'PORT': '',
        'USER': 'user',
        'PASSWORD': 'password',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
        },
    }
}


I get the following error:

Charlotte Wood

unread,
Jul 4, 2019, 3:11:01 PM7/4/19
to django...@googlegroups.com
It looks as if you have an odd value in there for the hour.  Do you?


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/58c14df7-0b4e-49dd-a19e-11c1101ff947%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Reitman

unread,
Jul 4, 2019, 3:47:22 PM7/4/19
to Django users
Don't you need to assign a port number?

John Burke

unread,
Jul 4, 2019, 4:48:21 PM7/4/19
to django...@googlegroups.com
I don't actually supply the hour.  This is code in base.py.  

The prior code sets up formatting:
datefirst = options.get('datefirst', 7)
cursor.execute('SET DATEFORMAT ymd; SET DATEFIRST %s' % datefirst)
I wonder if it is not getting executed successfully.



For more options, visit https://groups.google.com/d/optout.


--
Regards,
John B

John Burke

unread,
Jul 4, 2019, 4:48:40 PM7/4/19
to django...@googlegroups.com
For this particular instance, I don't need the port number.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.


--
Regards,
John B

Adnan Sadzak

unread,
Jul 5, 2019, 5:34:54 AM7/5/19
to Django users
Hi John,

You are probably passing datefirst as string while in your database datefirst column is int.
Can you please confirm you are not passing different data types?

Cheers,
Adnan


On Thursday, July 4, 2019 at 6:48:21 PM UTC+2, John Burke wrote:
I don't actually supply the hour.  This is code in base.py.  

The prior code sets up formatting:
datefirst = options.get('datefirst', 7)
cursor.execute('SET DATEFORMAT ymd; SET DATEFIRST %s' % datefirst)
I wonder if it is not getting executed successfully.


To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.


--
Regards,
John B

Joe Reitman

unread,
Jul 5, 2019, 2:53:54 PM7/5/19
to Django users
When does this error occur? During runserver or when executing a commit from your model?


On Thursday, July 4, 2019 at 11:48:40 AM UTC-5, John Burke wrote:
For this particular instance, I don't need the port number.

On Thu, Jul 4, 2019 at 11:47 AM Joe Reitman <jreit...@gmail.com> wrote:
Don't you need to assign a port number?

On Wednesday, July 3, 2019 at 6:52:35 PM UTC-5, John Burke wrote:
Trying to connect to SQL Server from Django

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'dbname',
        'HOST': 'hostname',
        'PORT': '',
        'USER': 'user',
        'PASSWORD': 'password',
        'OPTIONS': {
            'driver': 'ODBC Driver 13 for SQL Server',
        },
    }
}


I get the following error:
File "...\venv\lib\site-packages\sql_server\pyodbc\base.py", line 362, in init_connection_state
    val = cursor.execute('SELECT SYSDATETIME()').fetchone()[0]
ValueError: hour must be in 0..23


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.


--
Regards,
John B
Reply all
Reply to author
Forward
0 new messages