"[Error] Cannot read property '0' of undefined"

I’m unable to create a connection with my custom SQL database. Whatever I try I get the error message: '"[Error] Cannot read property ‘0’ of undefined"

Even when I try a simple console.log(). I can’t that error.

My script:

function create(user, callback) {
  //this example uses the "tedious" library
  //more info here: http://pekim.github.io/tedious/index.html
  const bcrypt = require('bcrypt');
  const sqlserver = require('tedious@1.11.0');

  const Connection = sqlserver.Connection;
  const Request = sqlserver.Request;
  const TYPES = sqlserver.TYPES;

  const connection = new Connection({
    userName:  'username',
    password:  'pass',
    server:    'blabla.database.windows.net',
    options:  {
      database: 'myDB'

  const query = 'INSERT INTO dbo.Users SET Email = @Email, Password = @Password';

  connection.on('debug', function(text) {
  }).on('errorMessage', function(text) {
    console.log(JSON.stringify(text, null, 2));
  }).on('infoMessage', function(text) {
    console.log(JSON.stringify(text, null, 2));

  connection.on('connect', function (err) {
    if (err) return callback(err);

    const request = new Request(query, function (err, rows) {
      if (err) return callback(err);
      // console.log('rows: ' + rows);

    bcrypt.hash(user.password, 10, function(err, hash) {
      if (err) return callback(err);
      request.addParameter('Email', TYPES.VarChar, user.email);
      request.addParameter('Password', TYPES.VarChar, hash);

Any idea what’s wrong?

1 Like

Welcome to Auth0 Community @woeterman94 :tada:

Can you check if you have any Hooks enabled in the Dashboard? That error typically means there is an uncaught/unhandled error in a Hook or Rule code and the output is being shown. Could you take a look at any enabled Hooks and maybe try testing with them disabled or review for where the error could be coming from. You can troubleshoot this further by using the Realtime Webtask Logs extension (https://auth0.com/docs/extensions/realtime-webtask-logs) to see any custom or console.log() text output.

Let me know if you can take a look at the above information.

Not using any hooks that could cause this issue i’m afraid. :frowning: