Hello all, decided to make a shift to having node js as a secondary programming language, in addition to C# being my primary. I am just wondering why the only time my node mssql connects properly is when i set a request.stream = true flag to true like here. And when its inside the code block sql.connect(config, err => { // ...
Okay so here is a full example of what does not work straight from the official documents:
async () => {
try {
// make sure that any items are correctly URL encoded in the connection string
await sql.connect(config)
const result = await sql.query'select * from AspNetUsers where FirstName = Troydon'
console.dir(result)
console.log(result)
} catch (err) {
// ... error checks
}
}
and here is one the only one that works and only when request.stream is set to true:
sql.connect(config, err => {
// ... error checks
const request = new sql.Request()
request.stream = true // You can set streaming differently for each request
request.query('select * from AspNetUsers') // or request.execute(procedure)
request.on('row', row => {
// Emitted for each row in a recordset
console.log(row); // print the whole row info
console.log(row.Id);
})
})
sql.on('error', err => {
// ... error handler
})
``` It also works when i connect directly to sql command in the terminal using : ` sqlcmd -S localhost -U sa -P passwd -d SampleDB -i ./CreateTestData.sql` *Note this is not a real password*