在网络服务器上通过 python 使用 Microsoft SQL
我正在尝试从 pylons (基于粘贴的)网络服务器对数据库运行一些查询,每次尝试导入我正在使用的 pymssql 库(其 这个 顺便说一句)我不断收到此错误:
tds_init_winsock: WSAEnumProtocols failed with 10055(WSAENOBUFS: No buffer space
available.)
在导入时。我还尝试使用 sqlalchemy 并在尝试制作 sqlalchemy 引擎时遇到完全相同的错误。我能做些什么来让它发挥作用吗?我没有连接到网络服务器或 pymssql 库,所以其他任何库都可以。
环境信息:
我使用的机器是32位win7台式机 服务器正在 python virtualenv 环境中运行,但 pymssql 库在虚拟环境中完美运行,只是不在服务器上运行
更新:
更多背景信息(和解释): 我不认为这是一个 MSSQL 问题,甚至在某种程度上也不是一个 Python 问题。有两个原因:A)当出现此问题时,我和其他人仍然可以连接到 MSSQL 数据库;B)如果不从服务器导入 pymssql,则它可以正常工作。不过,我确实认为这可能与 python 和 _mssql 处理套接字的方式和/或服务器处理套接字的方式有关...希望能有所帮助。
提前致谢
I'm trying to run some queries to a database from a pylons (paster-based) webserver and every time I try to import the pymssql Library I'm using (its this one by the way) I keep getting this error:
tds_init_winsock: WSAEnumProtocols failed with 10055(WSAENOBUFS: No buffer space
available.)
on the import. I also tried using sqlalchemy and get the exact same error when I try to make an sqlalchemy engine. Is there anything I can do to get this to work. I'm not attached to the webserver or the pymssql library so any others are fine.
Environment Information:
Machine I'm using is a32bit win7 desk top the
server is running in a python virtualenv environment, but the pymssql library works flawlessly in the virtual environment just not on the server
UPDATE:
A little more background information (and explanation):
I don't think that this is a MSSQL problem or even a python problem in a way. for two reasons: A) Me and others can still connect to the MSSQL database while this problem occurs and B) pymssql works perfectly fine if it isn't being imported from the server. I do however think It may have something to do with the way python and _mssql deal with sockets and/or the way the server deals with sockets... hope that helps a little more.
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误代码 WSAENOBUFS,同时翻译为“否”可用缓冲区空间”,实际上意味着(引用我刚刚指出的 MSDN 页面):
在实践中(如此处所解释)通常意味着(引用我刚刚指出的文章):
由于每个套接字在关闭后会在相当长的一段时间内保持“忙碌”状态(该文章称 240 秒),因此在中等繁忙的服务器上看到该数字(无论 Windows 7 中的值是多少)很容易超过也就不足为奇了,特别是因为桌面系统可能配置比实际服务器系统更少的套接字资源。
该文章指出了解决该问题的几种可能性,尽管它们已经过时了。但是,关键是,这似乎与 Python、Pylons、Paster 或 Pymssql 无关——这严格来说是 Windows 系统配置和控制的问题。因此,您可能会更幸运地在 serverfault.com 上提问,那里有精通服务器的系统管理人员!
Error code WSAENOBUFS, while translated into "No buffer space available", actually means (quoting the MSDN page I just pointed to):
and in practice (as explained e.g. here) usually means (quoting the article I just pointed to):
Since each socket stays "busy" for quite a while after it's closed (240 seconds, that article says) it wouldn't be surprising to see that number (whatever it may be in Windows 7) easily exceeded on a moderately-busy server, especially since a desktop system might well be configured with fewer socket resources than a real server system.
That article points to several possibilities for resolving the issue, though they're dated. But, the key point is that this seems to have nothing to do with Python, Pylons, Paster, or Pymssql -- it's strictly a problem of Windows system configuration and control. As such, you may have better luck asking on serverfault.com, where the server-savvy sysadms hang out!
好的。我终于让它完全正常工作了。如果在 python 中的套接字之后导入 pymssql 似乎会有一些问题,在 Web 服务器上的套接字之前导入它有点荒谬,所以我最终只是切换到 pyodbc,它与 pymssql 语法惊人地相似。绝对是一个很好的妥协...
Ok. I have finally gotten this completely working. pymssql seems to have some problems if it is imported after socket in python, importing it before sockets on a web server is a little ridiculous so I ended up just switching to pyodbc which is surprisingly similar to the pymssql syntax. Definitely a good compromise...
似乎有人在 http: 上发布了 pymssql 安装程序来解决此问题//code.google.com/p/pymssql/issues/detail?id=2。确保在运行此安装程序之前先卸载 pymssql,否则您可能仍会从损坏的版本中导入。
如果您安装了该egg,则应该可以通过从Python 安装目录(例如C:\Python26)下的lib\site-packages 中删除pymssql* 目录来卸载它。
It looks like someone has posted an installer for pymssql that fixes this problem at http://code.google.com/p/pymssql/issues/detail?id=2. Make sure to uninstall pymssql first before running this installer, or you may still end up importing from the broken version.
If you installed the egg, you should be able to uninstall it by deleting the pymssql* directory from lib\site-packages under your Python install directory (e.g. C:\Python26).