Node with MSSQL Outputting To Terminal/Connecting Issue

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 = 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'
    } catch (err) {
     // ... error checks

and here is one the only one that works and only when is set to true:

sql.connect(config, err => {
    // ... error checks
    const request = new sql.Request() = 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
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*

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.