Klevr Product Documentation logo

MS SQL Server Query Stage

The MS SQL Server Query stage allows a query or stored procedure to be run against an external MS SQL Server, with the results ingested as a new message.

Stage Overview

The MS SQL Server Query stage allows a query (or stored procedure) to be executed against an external MS SQL Server service. The results of the executed query (or stored procedure) are returned and ingested as a new message in Integration Hub, for further processing if required.

Support for using a Managed Identity for authentication was added in Integration Hub v5.0.0.

Stage Definition File Location

All MS SQL Server Query stages are defined by creating an appropriately formatted JSON definition file in the following location:

interfaces
{businessUnitCode}
{domainCode}
{integrationName}
qr
mssql
{STAGE_NAME}.json

Stage JSON Definition File Format

The JSON definition file for an MS SQL Server Query stage is as follows:

{
  "name": "mssql",
  "displayName": "Brief Stage Title",
  "description": "Brief description of the stage.",
  "type": "query|multiquery|storedproc|multistoredproc",
  "enabled": "$env:STATUS_<INTEGRATION_NAME>",
  "source": "source-event",
  "concurrency": 10,
  "sqlServerName": "$env:SQL_SERVER_NAME",
  "sqlDatabaseName": "$env:SQL_DATABASE_NAME",
  "sqlUsername": "$env:SQL_USERNAME",
  "sqlPassword": "$env:SQL_PASSWORD",
  "gateway": "$env:SQL_DATA_GATEWAY",
  "storedProcedure": "SP_NAME",
  "enableVnet": true,
  "preLogTransformSchemaFileName": "schemas/path/to/schema/schema-name.liquid",
  "preLogTransformSchemaType": "liquid|javascript",
  "preLogTransformFormat": "json|xml|csv"
}
PropertyDefinition
nameThe name of the stage.
displayNameOptional (but highly recommended). A short (3 or 4 word) "display name" for the stage, used as a "title" of the stage in the Integration Hub Portal service's self-documentation capability.
descriptionOptional (but highly recommended). A brief (10 to 15 word) description of the stage, used as a brief description of the stage's purpose in the Integration Hub Portal service's self-documentation capability. For a more detailed explanation (when needed), use the stage markdown feature.
typeRequired. One of query, multiquery, storedproc, or multistoredproc depending on whether the stage should execute a single SQL query, multiple SQL queries, a stored procedure, or multiple stored procedures on the MS SQL Server service.
When connecting to an on-premises MS SQL Server instance via On-Premises Data Gateway, it will not be possible to execute a SQL query via the query or multiquery modes. Only storedproc or multistoredproc will work with on-premises MS SQL Server instances.
enabledOptional boolean flag (true or false). Default is true.

Generally set via a DevOps variable. Controls if the stage is deployed enabled or not.
sourceThe source event that the stage subscribes to. See Pub/Sub Model.

Alternatively, sources may be supplied, and an array of one or more source events can be subscribed to.
concurrencyOptional number of concurrent runs permitted for the stage. Default is 10.
sqlServerNameRequired. The hostname/IP address of the MS SQL Server service that the query or stored procedure should be executed on.
sqlDatabaseNameRequired. The database name of the MS SQL Server service that the query or stored procedure should be executed on.
sqlUsernameOptional. The username that will be used to authenticate to the MS SQL Server service. If not provided, then the stage will authenticate using the Managed Identity of the Logic App.
sqlPasswordOptional. The password that will be used to authenticate to the MS SQL Server service. Required if the sqlUsername parameter is set.
gatewayOptional. On-premises MS SQL Server resources without a directly accessible hostname/IP address need to be accessed via an on-premises data gateway resource. If this is required, set this parameter to the Azure Resource ID of the resource, e.g. /subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Web/connectionGateways/{resource_name}
storedProcedureIf type is set to query or multiquery then storedProcedure must not be defined.

If type is set to storedproc, then storedProcedure must be defined, and is the name of the stored procedure to execute.

If type is set to multistoredproc then storedProcedure must not be defined. See the payload format below for multi-stored procedure operation.
enableVnetOptional. Boolean flag to indicate if the MS SQL Server connection should use VNet integration to ensure the use of a fixed IP address or not. Default value is false.

VNet integration is only supported when deploying using Standard Logic Apps.

Pre-Logging Transformation

This stage supports the optional pre-logging transformation feature using the following fields:

  • preLogTransformSchemaFileName
  • preLogTransformSchemaType
  • preLogTransformFormat

See the Pre-Logging Transformation for details.

Event Names

The MS SQL Server Query stage requires the use of a specific event name in subsequent stages, based on the type used.

The event used needs to be: qr-mssql-{TYPE_VALUE}-stage-name.

Stage Type{TYPE_VALUE}
queryquery
multiquerymultiquery
storedprocstoredproc
multistoredprocmultistoredproc

Payload Format

The MS SQL Server Query stage requires a payload when triggered.

Query Mode Payload Format

If operating in query mode, then the payload must be a JSON object that defines the query to execute, for example:

{
  "query": "SELECT * FROM table"
}

Multi-Query Mode Payload Format

If operating in multiquery mode, then the payload must be a JSON array of objects that defines the queries to execute, for example:

[
  {
    "query": "SELECT * FROM table1"
  },
  {
    "query": "SELECT * FROM table2"
  }
]

Stored Procedure Payload Format

If operating in storedproc mode, then the payload must be a JSON object that defines the stored procedure's parameters, for example:

{
  "param1": "value1",
  "param2": "value2"
  // etc.
}

In the event the stored procedure does not require any parameters, an empty JSON object must be passed:

{
}

Multi-Stored Procedure Payload Format

If operating in multistoredproc mode, then the payload must be a JSON array of objects that defines the stored procedures to execute, and their parameters, for example:

[
  {
    "storedProcedure": "SP_NAME_1",
    "parameters": {
      "param1": "value1",
      "param2": "value2"
      // etc.
    }
  },
  {
    "storedProcedure": "SP_NAME_2",
    "parameters": {
      // Empty object if no parameters required
    }
  }
]

Last updated on