简体   繁体   English

从 SQL 服务器调用 HANA 存储过程

[英]Call HANA stored procedure from SQL Server

I have defined a stored procedure in SAP HANA, with 3 IN parameters, that returns a recordset.我在 SAP HANA 中定义了一个带有 3 个IN参数的存储过程,它返回一个记录集。 It works perfectly from the HANA studio when I call it with the CALL sp_name (par1, par2, par3) syntax.当我使用CALL sp_name (par1, par2, par3)语法调用它时,它在 HANA 工作室中完美运行。

Now I need to call it from a Microsoft SQL Server (I am on 2016).现在我需要从 Microsoft SQL 服务器(我在 2016 年)调用它。 I have a remote linked server connection to the HANA server, which works ok when querying tables and views with both the HANADB..DBNAME.TABLENAME and the OPENQUERY(HANADB, 'SELECT...') syntax.我有一个到 HANA 服务器的远程链接服务器连接,当使用HANADB..DBNAME.TABLENAMEOPENQUERY(HANADB, 'SELECT...')语法查询表和视图时,它可以正常工作。

I tried hard, but I couldn't find a way to call remote procedures.我很努力,但我找不到调用远程过程的方法。 The 'CALL sp_name (p, p, p)' syntax returns an "object has no columns or current user has no authorizations" error. 'CALL sp_name (p, p, p)' 语法返回“对象没有列或当前用户没有授权”错误。

I also tried to create the stored procedure in HANA with the LANGUAGE SQLSCRIPT READS SQL DATA WITH RESULT VIEW ViewName .我还尝试使用LANGUAGE SQLSCRIPT READS SQL DATA WITH RESULT VIEW ViewName在 HANA 中创建存储过程。 Calling the view from within HANA is now a pain, since I have to use the PLACEHOLDER."$$parametername$$"=>'value' syntax, but it works.从 HANA 中调用视图现在很痛苦,因为我必须使用PLACEHOLDER."$$parametername$$"=>'value'语法,但它可以工作。 If I do that from SQL Server, I get an error如果我从 SQL 服务器执行此操作,则会收到错误消息

[SAP AG][LIBODBCHDB DLL][HDBODBC] General error;328 invalid name of function or procedure: viewname [SAP AG][LIBODBCHDB DLL][HDBODBC] 一般错误;328 function 或过程名称无效:viewname

Is there a way to call a stored procedure in HANA from SQL server?有没有办法从 SQL 服务器调用 HANA 中的存储过程?


More information: If I run the statement in SQL server without including parameters: SELECT * FROM OPENQUERY(hanadb, 'CALL MYDBNAME."MYSPNAME" ()');更多信息:如果我在 SQL 服务器中运行语句而不包含参数: SELECT * FROM OPENQUERY(hanadb, 'CALL MYDBNAME."MYSPNAME" ()');

I get this error:我收到此错误:

[SAP AG][LIBODBCHDB DLL][HDBODBC] General error;1281 wrong number or types of parameters in call: DATAIN is not bound: line 1 col 6 (at pos 5 [SAP AG][LIBODBCHDB DLL][HDBODBC] 一般错误;1281 调用中的参数数量或类型错误:DATAIN 未绑定:第 1 列第 6 行(在 pos 5

If I include the parameters, I get the error:如果我包含参数,则会收到错误消息:

Msg 7357, Level 16, State 2, Line 1 Could not process object "CALL MYDBNAME."MYSPNAME"('2021-01-01T00:00:00.000Z', '2021-02-01T00:00:00.000Z', 'TOLUENE')". MSG 7357,16级,State 2,第1行无法处理ZA8CFDE6331BD59EB259EB2AC96F896F8911C4B666666666Z“调用mydbname。甲苯')”。 The OLE DB provider "MSDASQL" for linked server "hanadb" indicates that the object has no columns or that the current user does not have the necessary permissions.链接服务器“hanadb”的 OLE DB 提供程序“MSDASQL”表明 object 没有列,或者当前用户没有必要的权限。

In the second case the error is generated by SQL server, while in the first by Hana.在第二种情况下,错误是由 SQL 服务器产生的,而在第一种情况下是由 Hana 产生的。 I don't know if there is a way to work around this.我不知道是否有办法解决这个问题。

please try like this.请尝试这样。 EXEC ('call schema_name.sp_name (''p1 value'',''p2 value'')') AT hana_linked_server_name EXEC ('call schema_name.sp_name (''p1 value'',''p2 value'')') AT hana_linked_server_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM