question

iwilson884 avatar image
iwilson884 asked ·

Alexa skill connecting to Azure database: connection login failed

I am trying to connect to an Azure database from an Alexa skill.

I have set up the 'salesdb' database in Azure (first time I have done this in Azure).

Have added the following code in the skill to connect to the database (along with a sample select statement to prove I can read from the database).


var Connection = require('tedious').Connection;

sessionAttributes.step=2;

var Request = require('tedious').Request;

sessionAttributes.step=3;


// Create connection to database

var config =

{

authentication: {

options: {

userName: 'mutiny', // update me

password: '********' // update me

},

type: 'default'

},

server: 'mutiny.database.windows.net', // update me

options:

{

database: 'salesdb', //update me

encrypt: true

}

}

sessionAttributes.step=4;

var connection = new Connection(config);

sessionAttributes.step=5;

console.log(config);


// Attempt to connect and execute queries if connection goes through

connection.on('connect', function(err)

{

if (err)

{

sessionAttributes.step=6;

console.log(err)

}

else

{

sessionAttributes.step=7;

queryDatabase()

}

}

);


function queryDatabase()

{

console.log('Reading rows from the Table...');


// Read all rows from table

var request = new Request(

"select count(*) from dbo.Customers where FirstName = 'Aaron'",

function(err, rowCount, rows)

{

console.log(rowCount + ' row(s) returned');

process.exit();

}

);


request.on('row', function(columns) {

columns.forEach(function(column) {

console.log("%s\t%s", column.metadata.colName, column.value);

});

});

connection.execSql(request);

}


On execution, sessionAttributes.step is set to 5, which suggests that the statement connection.on('connect', function(err) is failing.

The error message in the log is as follows:

019-10-31T13:00:14.574Z a718f162-01dd-4593-9a02-970287bac1ea { ConnectionError: Login failed for user ''.
at ConnectionError (/var/task/node_modules/tedious/lib/errors.js:12:12)
at Parser.<anonymous> (/var/task/node_modules/tedious/lib/connection.js:358:38)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
at Parser.<anonymous> (/var/task/node_modules/tedious/lib/token/token-stream-parser.js:54:15)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
at addChunk (/var/task/node_modules/readable-stream/lib/_stream_readable.js:291:12)
at readableAddChunk (/var/task/node_modules/readable-stream/lib/_stream_readable.js:278:11)
at Parser.Readable.push (/var/task/node_modules/readable-stream/lib/_stream_readable.js:245:10) message: 'Login failed for user \'\'.', code: 'ELOGIN' }


I have used the same login details to successfully connect to the database from SQL Server Management Studio, but it won't work with this code from the skill.

Any ideas what I need to do get this connection working between the skill and the Azure database? Not sure if the issue is with the skill code or with the setup of the database in Azure.


Could it be to do with the Azure firewall settings? I wasn't sure what IP address the Alexa skill is using, so have set up an IP address from 0.0.0.0 to 255.255.255.255 in the Azure firewall settings, just to see if I can make contact.

Thanks



alexa skills kitcertificationazure
1572540152546.png (50.6 KiB)
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

iwilson884 avatar image
iwilson884 answered ·

closing this off as I found the answer through another channel. If anyone needs the answer in the future, it was down to the version of tedious, needed this:

"tedious": "^5.0.3"

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.