简体   繁体   English

从BizTalk执行SQL存储过程

[英]Execute SQL stored procedure from BizTalk

I have three tasks to do in my BizTalk orchestration 我在BizTalk编排中要完成三个任务

  1. execute a stored procedure with dynamic parameters 使用动态参数执行存储过程
  2. do a insert into DB 插入数据库
  3. do a update in DB 在数据库中进行更新

Example data 示例数据

stored procedure [databasename].[storedprocedurename] 'param1Value', 'param2Value' 存储过程[databasename].[storedprocedurename] 'param1Value', 'param2Value'存储过程[databasename].[storedprocedurename] 'param1Value', 'param2Value'

table [databasename].[tablename] (id integer,desc nvarchar(50)) [databasename].[tablename] (id integer,desc nvarchar(50))

UPDATE 更新

Rephrase: Tasks are 改写:任务是

  1. How to call stored procedure from BizTalk orchestration with parameters from incoming XML message 如何使用传入XML消息中的参数从BizTalk业务流程中调用存储过程

  2. How to do insert into DB table from orchestration (and get back result of operation) 如何从业务流程插入数据库表(并返回操作结果)

  3. How to do update with dynamic "where' value conditions from incoming xml 如何使用传入XML中的动态“ where”值条件进行更新

There is full documentation here: Executing Stored Procedures in SQL Server by Using BizTalk Server 这里有完整的文档: 使用BizTalk Server在SQL Server中执行存储过程

High level overview: 高级概述:

  1. Create your stored procedure (eg usp_Test) to do your inserts/updates. 创建您的存储过程(例如usp_Test)以进行插入/更新。 Include parameter(s) that would be used in your WHERE clause(s). 包括将在您的WHERE子句中使用的参数。
  2. Use the Add->Add Generated Items->Consume Adapter Service to generate a schema and bindings file for the stored procedure. 使用“添加”->“添加生成的项”->“消费适配器服务”为存储过程生成架构和绑定文件。
  3. Create a map from your message to the stored procedure schema 从您的消息创建到存储过程架构的映射
  4. Update your Operation on the logical send port to match the SP name (usp_Test) 在逻辑发送端口上更新您的操作以匹配SP名称(usp_Test)
  5. Deploy your Application. 部署您的应用程序。
  6. Import the bindings for the physical send port from step 2 to your application 从步骤2将物理发送端口的绑定导入到您的应用程序
  7. Bind the orchestration to this send port (or create a filter on the send port, perhaps based on BTS.Operation ). 将业务流程绑定到此发送端口(或可能基于BTS.Operation在发送端口上创建过滤器)。
  8. Create ports with the map set on the send port you've imported and a filter se the Orchestration). 在导入的发送端口上设置映射并创建端口,并在业务流程中设置一个过滤器)。

BONUS: 奖金:

  1. Use table types to pass multiple inserts in a single call 使用表类型在单个调用中传递多个插入
  2. Use CompositeOperations to call multiple procedures/tableops 使用CompositeOperations调用多个过程/ tableops

CAVEATS: 注意事项:

  • The SQL Adapter doesn't like empty nodes (assuming you're using SQL Server). SQL适配器不喜欢空节点(假设您正在使用SQL Server)。 Make sure a node that is supposed to go in as a NULL is either set to xsi:nil=true (use the Nil functoid), or that it's not present in the destination (use a Value Mapping functoid, or a method to remove empty nodes in a pipeline or helper class ). 确保将以NULL形式进入的节点设置为xsi:nil=true (使用Nil xsi:nil=true ),或者在目标中不存在该节点(使用Value Mapping ,或使用方法来删除空值)管道或助手类中的节点 )。
  • Other adapters (Oracle or Db2 for example) will have their own particular challenges. 其他适配器(例如Oracle或Db2)将面临自己的特殊挑战。 IMO, the sqlBinding is the nicest to work with in terms of features available and documentation. IMO,就可用功能和文档而言,sqlBinding是最好的选择。 If you know your other platform, you should be able to figure out the issues. 如果您知道其他平台,则应该能够找出问题所在。
  • Avoid sending XML parameters unless you intend to store the XML in SQL Server. 除非您打算将XML存储在SQL Server中,否则避免发送XML参数。 In other words, don't make SQL Server shred XML when you have BizTalk to do that for you - BizTalk will almost certainly do a better job (performance and development wise). 换句话说,当您拥有BizTalk时,请勿使SQL Server切碎XML-BizTalk几乎可以肯定会做得更好(性能和开发方面)。
  • If you're returning data from SQL Server, consider using Strongly Typed (if your procedure result set is returned as a plain old SELECT or via OUTPUT parameters) or XML Polling (if your procedure returns a resultset using FOR XML ). 如果要从SQL Server返回数据,请考虑使用强类型(如果过程结果集是作为普通的旧SELECT或通过OUTPUT参数返回的)或XML轮询(如果过程使用FOR XML返回结果集)。 Avoid vanilla procedure calls unless you don't expect to deal with return data from the procedure. 除非您不希望处理该过程的返回数据,否则请避免使用普通的过程调用。

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

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