Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to connect a sql db with node and i find this npm package
https://www.npmjs.com/package/mssql[^]
and i started but i didn't make to

Java
var sql = require('mssql');

var config = {
    user: '',
    password: '',
    server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
    database: 'dbUsers'
}

sql.connect(config, function(err) {
// error check
  throw err; // not sure about this

    var request = new sql.Request();
    request.query('select * from tblUsers'); // or request.execute(procedure);

    request.on('recordset', function(columns) {
        // Emitted once for each recordset in a query
    console.log(columns);
    });

    request.on('row', function(row) {
console.log (row);
    });

});
Posted
Updated 12-Feb-15 4:37am
v2

1 solution

Just to be on the safe side, can you test the connection parameters to make sure they're correct? I found this open source project on the internet: DbAccess Tester[^].

Second, make sure "Mixed mode" authentication is enabled in Sql Server. And also that the user has login permission. This article covers both: http://kb.kcsi.ca/Knowledgebase/How-to-Change-from-Sql-Server-Windows-mode-to-Mixed-Mode-SQL-SERVER-2008[^]

*Note: You do not need to change the password. Also, the user doesn't have to be sa.

Finally restart management studio by right clicking the server name and clicking "Restart". Wait a few moments for the service to restart before proceeding.

Let me know if this doesn't help. We can then diagnose further.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900