I am working on an App that is authenticating user using Azure AD, extracting his accessToken and then using this token to connect to the Azure SQL server using below setting.
But unfortunately, I am getting ESOCKET "Connection lost - read ECONNRESET" right away,
const config = {
server: 'db-server-name.database.windows.net',
authentication: {
type: 'azure-active-directory-access-token',
options: {
token: cloudAccessToken
}
},
options: {
debug: {
packet: true,
data: true,
payload: true,
token: false,
log: true
},
database: 'DBNAME',
encrypt: true,
packetSize: 8192,
keepAlive:true,
requestTimeout: 300000,
connectionTimeout: 32000,
}
};
const connection = new Connection(config);
connection.on('connect', function (err) {
if (err) {
console.log(err);
}
executeStatement();
});
connection.on('debug', function (text) {
console.log(text);
});
connection.on('error', function (err) {
console.error(err); // --> this gets trigger with error ESOCKET right away
});
You must have missed something. The code is provided to you below. For specific operations, you can refer to Jim's answer.
And I have test it, it's works for me. I think it useful to you. For more details, you can refer to this post.
Connecting to Azure SQL using Service Principal in NodeJS, but token is rejected