0

I want to connect a sql db with node, so i find this npm package https://www.npmjs.com/package/mssql

I'am looking forward to create a simple authentication so for a start i just want to connect to the sql db, so my problem is when i tried to execute the existing code in mssql documentation i get an error here is what i executed :

   var sql = require('mssql');

   var config = {

   user: '...',   
    password: '...',
   server: 'localhost', 
    database: 'dbUsers'
    }

    sql.connect(config, function(err) {

     throw err; // error checks

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

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

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



  });
abderrahmen
  • 351
  • 1
  • 3
  • 14
  • Maybe you could tell us what the actual error you got was? – jpw Feb 12 '15 at 10:56
  • failed to connect to localhost:1433 connect ECONNREFUSED at Connection. – abderrahmen Feb 12 '15 at 11:06
  • Are you sure the server accepts connection over TCP/IP and that your login credentials are in order? – jpw Feb 12 '15 at 11:08
  • to tell you the truth it's my first interaction with sql server and i've been working with node a weak ago so i left the user and password field empty i thought it's default and for tcp/ip i don't know if there is a way to check that in sql server 2012 please tell me. thanks – abderrahmen Feb 12 '15 at 11:29
  • @abderrahmen check the udl file approach here: http://stackoverflow.com/questions/28478569/determine-sql-server-2012-connection-string/28478767#28478767 you can check if a connection to sql server can be made this way (see test connection button). the file will also store the connection string, so open it with a text editor to see the correct connection string. – rasso Feb 12 '15 at 13:55
  • @OzgurBar now when i've changed the server:localhost to server: 'ICEFOX-PC\\NODE' the error changed from not able to connect to localhost to login failed for user '...' so any ideas how i get the user and password from – abderrahmen Feb 13 '15 at 08:26
  • if you are able to login to sql server via management studio using windows authentication, you can actually create a login for node to connect. see the following link for details: https://msdn.microsoft.com/en-us/library/aa337562.aspx PS: Good to know you're making progress btw, as soon as you provide the correct login info, you'll be just fine:] – rasso Feb 13 '15 at 08:37
  • yees it works now you i've created a new user and password like @OzgurBar said and this is the code i get connected but the hard work still to come – abderrahmen Feb 13 '15 at 14:31

0 Answers0