Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

Connexion SQL Server au nœud js

Mettez votre var req = new sql.Request(conn) connexion à l'intérieur.

// config for your database
var config = {
    user: 'sa',
    password: 'mypassword',
    server: 'localhost', 
    database: 'SchoolDB' 
};

// connect to your database
sql.connect(config, function (err) {

    if (err) console.log(err);

    // create Request object
    var request = new sql.Request();

    // query to the database and get the records
    request.query('select * from Student', function (err, recordset) {

        if (err) console.log(err)

        // send records as a response
        res.send(recordset);

    });
});