2017-09-05 116 views
-1

我想連接到MS SQL數據庫使用節點JS但我收到以下錯誤。Nodejs連接SQL沒有連接

{ ConnectionError: Login failed for user 'Gurpanth'. at ConnectionError not connected

var express = require('express'); 
    var router = express.Router(); 

    /* GET home page. */ 
    router.get('/', function(req, res, next) { 
     GetData(function (recordSet) { 
      res.render('index', {product: recordSet}) 
     }); 
    }); 

    var Connection = require('tedious').Connection; 

    var config = { 
     userName: "Gurpanth", 
     password: "windowspassword", 
     server: "GURPANTH", 
     options: { 
      database: "NodeJSDb", 
      encrypt: true, 
     } 
    }; 

    var connection = new Connection (config); 

    connection.on('connect', function(err){ 
     console.log(err); 
     if(err!=null){ 
      console.log("not connected"); 
     } 
     else{ 
      console.log("Connected") 
      connection.close(); 
     }; 
    }); 
    module.exports = router; 

回答

0

你給我的錯誤信息表明您的用戶名和/或密碼不正確。該用戶是否存在於SQL Server中?