Answers for "node js and sql server"

SQL
1

mssql query node js

const sql = require('mssql')
const query=`select * from table`;
config = {
    database: "dbname",
  // can keep these option required with latest version of mssql npm package
    options: {
      enableArithAbort: true,
      encrypt: true,
      rowCollectionOnRequestCompletion: false,
    },
    parseJSON: true,
    password: "password",
    port: port, // if youe database running on difrent port then 1433
    server: "server ip or name",
    user: "usenme",
  };

 
sql.on('error', err => {
    // ... error handler
})
 
sql.connect(config).then(pool => {
    return pool.request()
        .query(query)
}).then(result => {
    console.log(result.recordset)
}).catch(err => {
    console.log(err)
});
Posted by: Guest on November-13-2020
0

connect ms sql to nodejs

var Connection = require('tedious').Connection;  
    var config = {  
        server: 'your_server.database.windows.net',  //update me
        authentication: {
            type: 'default',
            options: {
                userName: 'your_username', //update me
                password: 'your_password'  //update me
            }
        },
        options: {
            // If you are on Microsoft Azure, you need encryption:
            encrypt: true,
            database: 'your_database'  //update me
        }
    };  
    var connection = new Connection(config);  
    connection.on('connect', function(err) {  
        // If no error, then good to proceed.
        console.log("Connected");  
    });
    
    connection.connect();
Posted by: Guest on July-07-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language