WilliamRen / django-pyodbc

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

Can not connect to de DB using syncdb first time #80

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. python manage.py syncdb , in my django project 
2.- I get this error msg: Login failed for user 'sa'. But it works with the
same parameters using only pyodbc. The user 'sa' has all privileges on the DB. 

What is the expected output? What do you see instead?
Get the login and DataTables created in the remote SQLServer DB

What version of the product are you using? On what operating system?
-FreeTDS 0.82 v8
-unixODBC 2.3.0
-Ubuntu Linux

Please provide any additional information below.
-It works perfectly using only pyodbc within python shell, I get all the
rows from an specific table.

-Using django-pyodbc I get this....

python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File
"/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", 
line
362, in execute_manager
    utility.execute()
  File
"/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", 
line
303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File
"/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File
"/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
line 222, in execute
    output = self.handle(*args, **options)
  File
"/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
line 351, in handle
    return self.handle_noargs(**options)
  File
"/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.p
y",
line 49, in handle_noargs
    cursor = connection.cursor()
  File
"/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py",
line 81, in cursor
    cursor = self._cursor()
  File "/usr/local/lib/python2.6/django-pyodbc/sql_server/pyodbc/base.py",
line 225, in _cursor
    autocommit=autocommit)
pyodbc.ProgrammingError: ('42000', "[42000] [unixODBC][FreeTDS][SQL
Server]Login failed for user 'sa'. (18456) (SQLDriverConnectW)")

-------------------odbcinst.ini:
[FreeTDS]
Description             = FreeTDS 0.82 protocolo v8
Driver          = /usr/local/lib/libtdsodbc.so
Driver64                = /usr/local/lib/
Setup           = /usr/local/lib/libtdsodbc.so
Setup64         = /usr/local/lib/
UsageCount              = 1
CPTimeout               =
CPReuse         =

-----------------odbc.ini:
ODBC Data Sources]
JDBC = Sybase JDBC Server

[JDBC]
Driver          = /usr/local/lib/libtdsodbc.so
Description     = Sybase JDBC Server
Trace           = No
Servername      = JDBC
Database        = pubs2
UID             = guest

[Default]
Driver          = /usr/local/lib/libtdsodbc.so

[MSSQLTestServer]
Driver  = FreeTDS
Description = Sample database ODBC
Trace = No
Server = 10.1.2.240
Port = 1433

---------settings.py
MANAGERS = ADMINS
DATABASE_ENGINE = 'sql_server.pyodbc'           
DATABASE_NAME = 'codice_net_dist_test'            
DATABASE_USER = 'sa'           
DATABASE_PASSWORD = ''         
DATABASE_HOST = '10.1.2.240'             
DATABASE_PORT = '1433'             
DATABASE_OPTIONS = {            
            'driver':'FreeTDS',
            'dsn': 'MSSQLTestServer',         
}

Original issue reported on code.google.com by daesc...@gmail.com on 5 May 2010 at 12:38

GoogleCodeExporter commented 8 years ago
Hye guys! I got it!... The reason of this problem was that the DB user name 
didn't
have password, unfortunately I don't have admin access to the MSSQLServer DB to
modify the user, so I found that in the line 202 in the 
sql_server/pyodbc/base.py
file there is something like a "sql Injection" or some like that, then when the 
pass
string is empty, It crashes.. .

cstr_parts.append('UID=%s;PWD=%s' % (user_str, passwd_str))

So I fixed in this way...

cstr_parts.append('UID=%s;PWD=' % (user_str))

But you know, we have to fix it in a good way, adding a case to treat this 
user_str
string in this case.

See you guys, tnks.

Original comment by daesc...@gmail.com on 5 May 2010 at 1:41