如何在Mule 4中将表值参数传递给SQL Server存储过程?

时间:2019-03-20 16:31:45

标签: sql-server mule table-valued-parameters mulesoft

我需要将唯一ID列表从Mulesoft API传递到存储过程。期望该过程将返回表中与任何给定id相关的所有数据行。另一种方法是遍历列表并为每个ID调用过程,但我宁愿避免不可避免的性能损失。

在其他语言中,这可以通过传入表值参数并将其加入存储的proc中来实现。我已经找到了使用自定义类型herehere的文档,但是找不到关于如何在SQL Server中完成同一操作的文档。

根据上述文档,我尝试了以下配置。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
    <global-property doc:name="Global Property" doc:id="80f0a7ad-1d33-4b87-9db5-de5a0db885c1" name="env" value="dev" />
    <db:config name="SQL_Configuration" doc:name="Database Config" doc:id="8ecdec9f-fed6-4f86-891c-f5c7f05acf59" >
        <db:data-types>
                <db:data-type name="IntList" id="2002"/>
        </db:data-types>
        <db:mssql-connection host="${database.host}" user="${database.user}" password="${database.password}" databaseName="${database.name}" port="${database.port}">
            <db:connection-properties >
                <db:connection-property key="integratedSecurity" value="true" />
                <db:connection-property key="authenticationScheme" value="JavaKerberos" />
            </db:connection-properties>
        </db:mssql-connection>
    </db:config>
    <configuration-properties doc:name="Configuration properties" doc:id="d010957f-b05d-4aaa-af54-284a4220228f" file="config.${env}.yaml" />
</mule>

M子使配置停滞不前。这将导致以下错误:

org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 18; cvc-complex-type.2.4.a: Invalid content was found starting with element 'db:data-types'.

我还尝试了将参数定义为STRUCT而不在连接器配置中定义类型。当我确实以这种方式获得构建时,在运行时它会显示如下错误:

org.mule.runtime.core.internal.exception.MessagingException: The conversion from UNKNOWN to UNKNOWN is unsupported.;

当我尝试将参数定义为自定义类型并且尝试执行而根本不定义参数类型时,也会发生相同的错误,因此从错误消息中得出任何结论可能很容易。但是,如果将数据传递给驱动程序,这对我来说很有意义,但是它不知道如何将Mulesoft中的数组转换为用户定义的表类型,并将其用作存储proc中的参数。

我应该如何从Mulesoft定义TVP并将其传递给SQL Server存储过程?目前有可能吗?

0 个答案:

没有答案
相关问题