Web2Py 无法连接到 MSSQL

2024-04-28

我无法让 web2py 连接到 mssql。

<type 'exceptions.RuntimeError'>(Failure to connect, tried 5 times:
'NoneType' object has no attribute 'connect')

我的连接字符串是:

db = DAL('mssql://testUser:password1@localhost/testDB') 

环境
Windows Server 2008 R2,64 位操作系统
SQL Server 2008 R2,本地。
Web2py:源代码安装版本1.99.2(2011-09-26 06:55:33)稳定。
pyodbc
Python 2.7.2

我已经测试过可以使用 pyodbc 连接。以下代码有效:

import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=testDB;UID=testUser;PWD=password1')
cursor = cnxn.cursor()
cursor.execute("select * from tbUsers")
rows = cursor.fetchall()
for row in rows:
  print row

谢谢你的时间。

Corey.


我刚刚收到 Massimo Di Pierro 的解决方案Web2Py 论坛 http://groups.google.com/group/web2py/browse_thread/thread/d21ce33c1b843ef2。他推断出原因并提供了解决方法。

不确定是否需要“导入 pyodbc”。一旦驱动程序被分配,它就会保留下来,即使在服务器重新启动后也是如此。

# Test if the mssql driver is assigned. Sets it up if it isn't.
import pyodbc
from gluon.dal import MSSQLAdapter
if not (MSSQLAdapter.driver):
  MSSQLAdapter.driver = globals().get('pyodbc',None)

db = DAL('mssql://testUser:password@localhost/testDB')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Web2Py 无法连接到 MSSQL 的相关文章

随机推荐