Auth0 Home Blog Docs

Connection to Azure SQL Server not working inside rule



I’ve created a rule from the “Add user roles from a SQL Server database” template.
I’ve modified the code with my credentials and a custom query, both fully functional.
However, I’m getting this message:

ERROR: Script execution did not complete within 20 seconds. Are you calling the callback function?

Any idea of what’s going on? I’m also getting the following on the Webtask log:

finished webtask request 1XXXXXXXXX with HTTP 500 in 35062ms
(changed the code with Xs).

The query and credentials are correct as I’m using them constantly without problems.



Managed to solve it by creating the connection myself using mssql.


How did you manage to solve this using the connection string yourself? I’m struggling with the same problem


Hi, sorry for the late reply, hope it’s not to late to help out. This is the code I used:

function (user, context, callback) {

var mssql = require(‘mssql@3.3.0’);
var connection = mssql.connect({ user:
’’, password: ‘’, server: ‘’,
database: ‘’, options: { encrypt:
true, } }).then(function(pool) {
return pool.request() .query(‘YOUR
QUERY’); }).then(function(result) { //
user, context); }); }


I can’t for the life of me get the code to look good, hope it’s clear enough


Thanks a lot! I’ll try this out


Awwww damn, it actually works! You’re a lifesaver!


@baltzar Glad I could help!


I’ll share my code, with an example of replacing parameters to avoid sql injection:

function (user, context, callback) {
  var mssql = require('mssql@3.3.0');
  var query = "SELECT ur.Name " +
                "FROM dbo.Users u " +
                "INNER JOIN dbo.UserRoleUsers urr " + 
                "ON urr.User_UserId = u.UserId " +
                "INNER JOIN dbo.UserRoles ur " +
                "ON ur.Id = urr.UserRole_Id " + 
                "WHERE u.Email = @email";
  var connection = mssql.connect( { 
    user: '', 
    password: '', 
    server: '', 
    database: '',
    options: {
      encrypt: true
  }).then(function(pool) {
    return pool.request()
      // To avoid sql injection
      .input("email", mssql.VarChar,
  }).then(function(result) {
    context.idToken""] = result;
    callback(null, user, context);