2014-08-28 53 views
0

嗨有一種方法來使用django-pyodbc普及數據庫?我嘗試不同的設置,但是當我嘗試從數據庫中創建一個模型來檢查db時,它向我顯示這個錯誤,但是我可以在python pyodbc中創建查詢。django pyodbc和普及數據庫

`( '42000', '[42000] [普適] [ODBC客戶端接口] [LNA] [普適] [ODBC 引擎接口]無效SET語句(0)(SQLExecDirectW)。') 請求方法: GET 請求URL:
Django的版本:1.6.6 異常類型:ProgrammingError 異常值:
( '42000',「[42000] [普及] [ODBC客戶端界面] [LNA] [普及] [ODBC引擎接口]無效的SET語句。 (0)(SQLExecDirectW)') 異常位置:C:\ Python27 \ lib \ site-packages \ django_pyodbc \ base.py在_cursor中,第296行 Python執行能:C:\ Python27 \ python.exe Python版本:2.7.8

cursor.execute("SET DATEFORMAT Ymd; SET DATEFIRST %s" % self.datefirst) 
pyodbc.ProgrammingError: ('42000', '[42000] [Pervasive][ODBC Client Interface][LNA][Pervasive]      [ODBC Engine Interface]Invalid SET statement. (0) (SQLExecDirectW)')` 

,這是件錯誤的,當我嘗試在數據庫上運行inspectdb。

根據主要問題是在這個文件base.py第296行是一個問題,在odbc驅動程序上的set語句這是base.py上的一段代碼我嘗試評論,但在另一件事情出現後。

`cursor.execute("SET DATEFORMAT Ymd; SET DATEFIRST %s" % self.datefirst) 
     if self.ops.sql_server_ver < 2005: 
      self.creation.data_types['TextField'] = 'ntext' 
      self.features.can_return_id_from_insert = False 

     ms_sqlncli = re.compile('^((LIB)?SQLN?CLI|LIBMSODBCSQL)') 
     self.drv_name = self.connection.getinfo(Database.SQL_DRIVER_NAME).upper() 

     # http://msdn.microsoft.com/en-us/library/ms131686.aspx 
     if self.ops.sql_server_ver >= 2005 and ms_sqlncli.match(self.drv_name) and           self.MARS_Connection: 
      # How to to activate it: Add 'MARS_Connection': True 
      # to the DATABASE_OPTIONS dictionary setting 
      self.features.can_use_chunked_reads = True` 

回答

0

檢查您的訪問權限。錯誤消息指示語法錯誤,但根據mssql support site,錯誤代碼42000是「語法錯誤或訪問衝突」。

0

嘗試把單引號%左右S:

cursor.execute("SET DATEFORMAT Ymd; SET DATEFIRST '%s'" % self.datefirst)