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
});