2012-09-06 36 views
0

我需要通过callproc调用“sp_executesql”(我需要它作为RPC)的帮助。这是我的代码:pymssql callproc unicode - 返回错误

import pymssql 
conn = pymssql.connect(host='11.22.33.44:1433', user='sa', password='XYZ', database='AdventureWorks') 
cur = conn.cursor() 
cur.callproc("sp_executesql", 'SELECT * FROM AdventureWorks.HumanResources.Employee WHERE BusinessEntityID = 109') 

我得到这个错误:

File "executesql.py", line 4, in <module> 
    cur.callproc("sp_executesql", 'SELECT * FROM AdventureWorks.HumanResources.Employee WHERE BusinessEntityID = 109') 
    File "pymssql.pyx", line 357, in pymssql.Cursor.callproc (pymssql.c:4238) 
    self._returnvalue = proc.execute() 
    File "_mssql.pyx", line 1289, in _mssql.MSSQLStoredProcedure.execute (_mssql.c:12177) 
    check_cancel_and_raise(rtc, self.conn) 
    File "_mssql.pyx", line 1322, in _mssql.check_cancel_and_raise (_mssql.c:12473) 
    return maybe_raise_MSSQLDatabaseException(conn) 
    File "_mssql.pyx", line 1366, in _mssql.maybe_raise_MSSQLDatabaseException (_mssql.c:13067) 
    raise ex 
_mssql.MSSQLDatabaseException: (214, "Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.DB-Lib error message 214, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n") 

运行其他存储过程的顺利进行。 运行字符串为Unicode(u'Select ......“)给出了这样的错误:

Traceback (most recent call last): 
    File "executesql.py", line 4, in <module> 
    cur.callproc("sp_executesql", u'SELECT * FROM AdventureWorks.HumanResources.Employee WHERE BusinessEntityID = 109') 
    File "pymssql.pyx", line 354, in pymssql.Cursor.callproc (pymssql.c:4177) 
    raise NotSupportedError('Unable to determine database type') 
pymssql.NotSupportedError: Unable to determine database type 

你知道如何克服呢?版本(c)Windows NT 6.1上的微软公司企业版(64位)(内部版本7601:Service Pack,版本7601) 1)(管理程序)

非常感谢

回答

0

我遇到了同样的问题。似乎已在Issue 56中报告。 到目前为止尚未解决。 :(

更新:我发现了一个解决“无”的问题,请参见我的线程here

+0

谢谢,@Mike我看到这个“第56期”你被引用,但我无法找到。来源,它的报告已经改变了,你知道它们在哪里吗?我并不介意在修复这个bug后从头开始构建整个东西。 – roi

+0

转到下载部分并为你的系统下载/提取版本。到根目录下的pymssql.pyx文件,我不认为他们改变了项目版本,也许只是他们的本地副本,我正在考虑尝试修复,如果你修复它,尽管如此,请参阅Randy的帖子。 Google小组了解如何使其成为该项目的一部分。有关链接,请访问https://groups.google.com/forum/?hl=zh-CN&fromgroups=#!topic/ pymssql/lACWoHmAcvI – Mike

+0

@roi,你能编译?当我编译生成的文件不起作用。 – Mike