pymssql callproc unicode - 返回错误

时间:2012-09-06 10:03:47

标签: python sql-server unicode pymssql

我需要帮助调用" sp_executesql"通过callproc(我需要它作为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&#39;选择...&#39;)会出现此错误:

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是 Microsoft SQL Server 2012 - 11.0.2100.60(X64)2012年2月10日19:39:15版权所有(c)Windows NT 6.1(Build 7601:Service Pack 1)上的Microsoft Corporation Enterprise Edition(64位)(Hypervisor)

非常感谢

1 个答案:

答案 0 :(得分:0)

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

更新:我找到了&#34;无&#34;的解决方案。问题。请参阅我的帖子here