Web2Py 无法连接到 MSSQL
我无法让 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
感谢您的宝贵时间。
科里.
I'm unable to get web2py to connect to mssql.
<type 'exceptions.RuntimeError'>(Failure to connect, tried 5 times:
'NoneType' object has no attribute 'connect')
My connection string is:
db = DAL('mssql://testUser:password1@localhost/testDB')
Environment
Windows Server 2008 R2, 64-bit operating system
SQL Server 2008 R2, local.
Web2py: source code install version 1.99.2 (2011-09-26 06:55:33) stable.
pyodbc
Python 2.7.2
I've tested that I can connect using the pyodbc. The following code works:
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
Thanks for your time.
Corey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在 Web2Py 论坛上收到 Massimo Di Pierro 发来的解决方案。他推断出原因并提供了解决方法。
不确定是否需要“导入 pyodbc”。一旦驱动程序被分配,它就会保留下来,即使在服务器重新启动后也是如此。
I've just received a solution from Massimo Di Pierro on the Web2Py forum. He deduced the cause and provided a work around.
Not sure if the "import pyodbc" is needed. Once the driver was assigned it stayed, even after a restart of the server.
确认您的登录正确并且安装了 pyodbc 后,如果您的数据库服务器名称中包含反斜杠(例如 localhost\dbServerName),请确保服务器的连接字符串如下:
您也可以用 IP 地址替换本地主机。
环境:
Windows 7 Professional,32位操作系统
SQL Server 2008 R2 通过网络连接
Web2py:源代码安装版本2.4.6稳定
pyodbc:pyodbc-3.0.5.win32-py2.7.exe
Python 2.7.3
After confirming that your login is correct and that you have pyodbc installed, be sure that the connection string for the server is as follows if your db server name has a backslash in it (e.g. localhost\dbServerName):
You can substitute the localhost with an IP Address as well.
Environment:
Windows 7 Professional, 32-bit operating system
SQL Server 2008 R2 connecting over a network
Web2py: source code install version 2.4.6 stable
pyodbc: pyodbc-3.0.5.win32-py2.7.exe
Python 2.7.3