We've now given-up on the SQL binding as it's just too restrictive at the moment. For running a simple DB query with one or two inputs it's fine, but anything else is no good. For anyone else who finds this question in the future, the steps required (for a Node function app) were -
- Install the MSSQL module from NPM on the parent Function App (using a package.json file and Kudu to install, see functions-reference-node )
- Importing MSSQL in the index.js for each function
- Create a connection with the parent connection string, submit the request, and make sure to close the connection again to avoid any problems down the line
Example function.json -
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "testFunction/{queryString}",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
index.js -
const sql = require('mssql')
module.exports = async function (context, req) {
sql.on('error', err => {
sql.close()
return {
status: 500,
body: 'DB connection error'
}
})
try {
if (req.body) {
const pool = await sql.connect(process.env.SqlConnectionString)
const result = await pool.request()
.input('postProperty1', sql.Int, req.body.property1)
.input('postProperty2', sql.NVarChar(128), req.body.property2)
.input('queryProperty3', sql.NVarChar(sql.MAX), context.bindingData.queryString)
.execute('SP_StoredProcedure')
sql.close()
context.res = {
status: 200,
body: result.recordset
}
} else {
context.res = {
status: 400,
body: "POST details not found"
}
}
}
catch (e) {
context.log(e)
return {
status: 404,
body: 'Unexpected error during operation'
}
}
}