本文介绍了如何使用django-mssql连接到SQL Server 2008 R2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我不能得到django连接sql server 2008 r2。我在我们的服务器和sql服务器上有管理权限。我已经构建了Windows Server 2008 sp2的虚拟窗口框,因为我以为我可能会有一些运气与django-mssql。我已经在Windows框上尝试过django-pyodbc和django-mssql,但尚未成功。这是我的数据库设置:

  DATABASES = {
'default':{
'ENGINE' 'sqlserver_ado',#还试过sql_server.pyodbc
'NAME':'TMSEPLAY',
'USER':'***',#省略为
'PASSWORD':' *******',#省略为
'HOST':'172.16.1.14',
'PORT':'1434',
'选项':{
'provider':'SQLCLI10',#还试过'SQLCLI11'和'SQLOLEDB'
'extra_params':'DataTypeCompatibility = 80'
}
}
}

我得到的错误:

  C:\Python27\CourseData\mysite> manage.py syncdb 
追溯(最近的最后一次调用):
文件C:\Python27\CourseData\\ \\mysite\manage.py,第10行,在< module>
execute_from_command_line(sys.argv)
文件C:\Python27\lib\site- packages\django\core\management\__init __。py,行
443,在execute_from_command_line
utility.execute()
文件C:\Python27\lib\site- packages\django\core\management\__init __。py,行
382,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件C:\Python27\lib\site-packages\django\core\\ \\ management\base.py,第196行,
在run_from_argv
self.execute(* args,** options .__ dict__)
文件C:\Python27\lib\\ \\ site-packages\django\core\management\base.py,第232行,
在执行
output = self.handle(* args,** options)
文件C:\Python27\lib\site-packages\django\core\management\base.py,行371,
在句柄
return self.handle_noargs(* *选项)
文件C:\Python27\lib\site- packages\django\core\management\commands\syncdb.py
,第57行,handle_noargs
cursor = connection.cursor()
文件C:\Python27\lib\site- packages\django\db\backends\__init __。py,第306行
cursor
cursor = self.make_debug_cursor(self._cursor())
文件C:\Python27\lib\site-packages\sqlserver_ado\base.py,第193行, _curs

self .__ connect()
文件C:\Python27\lib\site-packages\sqlserver_ado\base.py,第168行,__con
nect
use_transactions = self.use_transactions,
文件C:\Python27\lib\site-packages\sqlserver_ado\dbapi.py,第151行,conn
ect
raise OperationalError(e,打开连接错误+ connection_string)
sqlserver_ado.dbapi.OperationalError:(com_error(-2147352567,'Exception occurredre
d。',(0,u'ADODB.Connection',u'Provider找不到。它可能不是正确的
安装。',u'C:\\Windows\\HELP\\ADO270.CHM',1240655,-2146824582),无),'E
rror opening connection:DATA SOURCE = 172.16.1.14,1434; Network Library = DBMSSOCN; I
nitial Catalog = TMSEPLAY; UID = ***; PWD = ********; PROVIDER = SQLCLI10; MARS Connection = Tr
ue; DataTypeCompatibility = 80; MARS Connection = True')

I感谢任何见解。谢谢。

解决方案

我可以在该日志中看到一条错误消息:



$打开连接错误:DATA SOURCE = 172.16.1.14 port:1434



所以我会看到所有的实例是否正在运行,并可以通过端口1434在该机器上访问。



此外,以下可能有帮助:


I cannot figure out why I cannot get django to connect with sql server 2008 r2. I have administrative privileges on our server and on sql server. I have constructed a virtual windows box with windows server 2008 sp2 because I thought I might have some luck with django-mssql. I've tried both django-pyodbc and django-mssql on the windows box but have not yet succeeded. Here are my db settings:

DATABASES = {
    'default': {
        'ENGINE': 'sqlserver_ado',  # Have also tried sql_server.pyodbc
        'NAME': 'TMSEPLAY',
        'USER': '***', # Omitted for post
        'PASSWORD': '*******', # Omitted for post
        'HOST': '172.16.1.14',
        'PORT': '1434',
        'OPTIONS': {
            'provider': 'SQLCLI10', # Have also tried 'SQLCLI11' and 'SQLOLEDB'
            'extra_params': 'DataTypeCompatibility=80'
            }
    }
}

The error I get:

C:\Python27\CourseData\mysite>manage.py syncdb
Traceback (most recent call last):
  File "C:\Python27\CourseData\mysite\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 371,
 in handle
    return self.handle_noargs(**options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py"
, line 57, in handle_noargs
    cursor = connection.cursor()
  File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 306,
 in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 193, in _curs
or
    self.__connect()
  File "C:\Python27\lib\site-packages\sqlserver_ado\base.py", line 168, in __con
nect
    use_transactions=self.use_transactions,
  File "C:\Python27\lib\site-packages\sqlserver_ado\dbapi.py", line 151, in conn
ect
    raise OperationalError(e, "Error opening connection: " + connection_string)
sqlserver_ado.dbapi.OperationalError: (com_error(-2147352567, 'Exception occurre
d.', (0, u'ADODB.Connection', u'Provider cannot be found. It may not be properly
 installed.', u'C:\\Windows\\HELP\\ADO270.CHM', 1240655, -2146824582), None), 'E
rror opening connection: DATA SOURCE=172.16.1.14,1434;Network Library=DBMSSOCN;I
nitial Catalog=TMSEPLAY;UID=***;PWD=********;PROVIDER=SQLCLI10;MARS Connection=Tr
ue;DataTypeCompatibility=80;MARS Connection=True')

I'd appreciate any insight. Thanks.

解决方案

I can see an error message in that log:

$Error opening connection: DATA SOURCE=172.16.1.14 port:1434

So I would see if all instances are running and is accessible on that machine through port 1434.

Also, the following may help:Setting up django-mssql issues

这篇关于如何使用django-mssql连接到SQL Server 2008 R2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 09:40