google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Driver's SQLSetConnectAttr failed (0) (SQLDriverConnectW) on admin interface #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. django-admin.py startproject django_smalltest
2. manage.py startapp smalltest
3. Add an existing database table to smalltest.models.py
4. Configure settings.py database parameters
5. Add django.contrib.admin and django_smalltest.smalltest
6. Enable admin interface in site's urls.py
7. Create smalltest.admin.py and register the model created in step 3.

What is the expected output? What do you see instead?

I get prompted for the username and password for access to the admin interface. 
Django 
connects to the database (I see the connection string because I added a print 
statement right 
before line 146 in sql_server.pyodbc.base.py) and validates that I'm a proper 
user. It then (I think) 
tries to render the main admin page and dies with the error message in the 
traceback.

After the traceback below I included a simple python script using pyodbc that 
manages to 
connect to the database and run queries correctly. I also added the output of 
runserver with my 
print statements and some notes.

The very same django application running the very same django, django-pyodbc, 
pyodbc 
versions, runs just fine in Mac OS X with a TDS driver.

What version of the product are you using? On what operating system?
Python 2.6
pyodbc-2.1.3
Django-PyODBC rev. 151
Django 1.1 alpha 1 SVN-9956

Original issue reported on code.google.com by ce.lo...@gmail.com on 2 Mar 2009 at 4:20

GoogleCodeExporter commented 9 years ago
I'm sorry. My post was truncated... Here is the remainder of the information:

Running on Windows 2003 server 
ODBC driver info: Microsoft SQL Native Client Version 09.00.1399

Please provide any additional information below.

Database config from settings.py:

DATABASE_ENGINE = 'sql_server.pyodbc'
DATABASE_ODBC_DRIVER = 'SQL Native Client'
DATABASE_NAME = 'blah'
DATABASE_USER = 'blah'
DATABASE_PASSWORD = 'blah'
DATABASE_HOST = r'BLAH'
DATABASE_OPTIONS= {'MARS_Connection': True}

-----------------
Traceback:

Environment:

Request Method: POST
Request URL: http://navajo:8000/admin/
Django Version: 1.1 alpha 1 SVN-9912
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django_smalltest.smalltest']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')

Traceback:
File "C:\django\django-trunk\django\core\handlers\base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\django-trunk\django\contrib\admin\sites.py" in wrapper
  156.                 return self.admin_view(view)(*args, **kwargs)
File "C:\django\django-trunk\django\contrib\admin\sites.py" in inner
  146.             if not self.has_permission(request):
File "C:\django\django-trunk\django\contrib\admin\sites.py" in has_permission
  107.         return request.user.is_authenticated() and request.user.is_staff
File "C:\django\django-trunk\django\contrib\auth\middleware.py" in __get__
  5.             request._cached_user = get_user(request)
File "C:\django\django-trunk\django\contrib\auth\__init__.py" in get_user
  83.         user_id = request.session[SESSION_KEY]
File "C:\django\django-trunk\django\contrib\sessions\backends\base.py" in 
__getitem__
  46.         return self._session[key]
File "C:\django\django-trunk\django\contrib\sessions\backends\base.py" in 
_get_session
  172.                 self._session_cache = self.load()
File "C:\django\django-trunk\django\contrib\sessions\backends\db.py" in load
  16.                 expire_date__gt=datetime.datetime.now()
File "C:\django\django-trunk\django\db\models\manager.py" in get
  93.         return self.get_query_set().get(*args, **kwargs)
File "C:\django\django-trunk\django\db\models\query.py" in get
  337.         num = len(clone)
File "C:\django\django-trunk\django\db\models\query.py" in __len__
  161.                 self._result_cache = list(self.iterator())
File "C:\django\django-trunk\django\db\models\query.py" in iterator
  281.         for row in self.query.results_iter():
File "C:\django\django-trunk\django\db\models\sql\query.py" in results_iter
  254.         for rows in self.execute_sql(MULTI):
File "C:\django\django-trunk\django\db\models\sql\query.py" in execute_sql
  2027.         cursor = self.connection.cursor()
File "C:\django\django-trunk\django\db\backends\__init__.py" in cursor
  62.         cursor = self._cursor(settings)
File "C:\django\django-pyodbc\sql_server\pyodbc\base.py" in _cursor
  146.             self.connection = Database.connect(connstr, autocommit=self.options['autocommit'])

Exception Type: Error at /admin/
Exception Value: ('IM006', "[IM006] [Microsoft][ODBC Driver Manager] Driver's 
SQLSetConnectAttr failed (0) 
(SQLDriverConnectW); [01000] [Microsoft][SQL Native Client][SQL Server]Changed 
database context to 'ndrdb'. 
(5701); [01000] [Microsoft][SQL Native Client][SQL Server]Changed language 
setting to us_english. (5703)")

--------------

Pyodbc script with said connection that works correctly:

import pyodbc

cnxn = pyodbc.connect('DRIVER={SQL Native 
Client};SERVER=KNUTH;UID=blah;PWD=blah;DATABASE=blah')
cursor = cnxn.cursor()
print 'Driver name : ' + cnxn.getinfo(pyodbc.SQL_DRIVER_NAME)
cursor.execute("select count(*) from blah")
for row in cursor:
    print 'Number of blah in blah: '
    print row[0]

-----------------

Django version 1.1 alpha 1 SVN-9956, using settings 'django_smalltest.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CTRL-BREAK.
DRIVER={SQL Native 
Client};SERVER=blah;UID=blah;PWD=blah;DATABASE=blah;MARS_Connection=yes
[02/Mar/2009 11:14:40] "GET /admin/ HTTP/1.1" 200 1748

=> The above was my original request for the admin interface
=> The below happens after providing username and password

DRIVER={SQL Native 
Client};SERVER=blah;UID=blah;PWD=blah;DATABASE=blah;MARS_Connection=yes
DRIVER={SQL Native 
Client};SERVER=blah;UID=blah;PWD=blah;DATABASE=blah;MARS_Connection=yes
[02/Mar/2009 11:14:54] "POST /admin/ HTTP/1.1" 500 116153

Original comment by ce.lo...@gmail.com on 2 Mar 2009 at 4:24

GoogleCodeExporter commented 9 years ago
If I'm understanding things correctly, the only obvious difference between the
connection string used by your standalone script and the one used by 
django-pyodbc
project is:

MARS_Connection=yes

So, what happens when you leave out

DATABASE_OPTIONS= {'MARS_Connection': True}

from your settings

Original comment by cra...@gmail.com on 2 Mar 2009 at 5:54

GoogleCodeExporter commented 9 years ago
Sigh... Please close this incident.

I updated the SQL Server Native Driver to the lastest available (obtained from: 
http://www.microsoft.com/downloads/details.aspx?FamilyId=50b97994-8453-4998-8226
-
fa42ec403d17&displaylang=en) and it works like a charm.

The previous driver version (causing this issue) was 2005.90.1399.00, the 
latest driver version I just installed 
is 2005.90.3042.00. I check the versions on the ODBC Manager's driver tab.

Thanks and sorry for bringing a non-django-pyodbc issue to the forum. It might 
help someone else seeing 
the same error though.

Thanks!

Original comment by ce.lo...@gmail.com on 2 Mar 2009 at 6:34

GoogleCodeExporter commented 9 years ago
Whew I had this error, thanks so much for posting -- was VERY HELPFUL.  Am 
updating
my driver version now, hope this fixes it.  Of course, a single dll driver 
install
takes 5 minutes and forces a reboot.  That's a separate issue though....

Original comment by itera...@gmail.com on 9 Mar 2009 at 11:06

GoogleCodeExporter commented 9 years ago
Closing, as requested by the original poster.

Furtunately it effectively helped another user :)

Original comment by cra...@gmail.com on 12 May 2009 at 2:14

GoogleCodeExporter commented 9 years ago
Had the same issue and updating the driver fixed the issue. Thanks for the post.
When google-ing MS Sql Native Driver download I got the 1399 version.

Finnur

Original comment by finnur.e...@gmail.com on 26 Apr 2010 at 2:17