我需要通过callproc调用"sp_executesql“的帮助(我需要它作为RPC)。这是我的代码:
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你知道如何克服这个问题吗?
SQL Server is Microsoft SQL Server 2012 - 11.0.2100.60 (X64) Feb 10 2012 19:39:15版权所有(c) Windows NT 6.1 (Build 7601: Service Pack 1) (虚拟机管理程序)上的Microsoft Corporation Enterprise Edition (64位)
非常感谢
发布于 2012-10-18 01:10:26
我也遇到了同样的问题。这似乎已经在Issue 56上被报道过了。到目前为止还没有解决。:(
更新:我找到了一个解决“无”问题的方法。请参阅我的线程here。
https://stackoverflow.com/questions/12297589
复制相似问题