0

我尝试使用 node-mssql( https://github.com/patriksimek/node-mssql/issues ) 来连接 mssql。这是我的配置:

export class Config {
   static db = {

    server: ...,
    user: ....,
    password: ....,
    database:...,

  }
}  

这是我的连接代码

sql.connect(Config).then(function(){
    new sql.Request().query('SELECT * FROM ABC_2016.dbo.device')        .
                     .then(recordset=>console.log(recordset))
                     .catch(err =>console.log(err));

这是我的错误: (intermediate value).query(...).then 不是函数。

我不知道为什么会这样!!

有人帮助我!

4

2 回答 2

0

尝试使用多连接方法...

就像这样 :

var conn1 = new sql.Connection(config, function(error){
    if(error){
        console.log(error)
    } else {
       var request = new sql.Request(conn1);

        request
        .input('project_id', sql.Int,project_id)
        .query('SELECT * from TableName WHERE [project_id] = @project_id ORDER BY [id] ')
        .then(function(data) { 
            console.log(data)
        }).catch(function(error) {
            console.log(error);
        }); 
    }
 });
于 2016-12-04T19:46:25.660 回答
0

试试下面的方法

var webconfig = {

user: 'login',

password: 'sa@123',

server: 'localhost', 

database: 'TestDB',



options: {

    encrypt: false // Use this if you're on Windows Azure 

}

  }




 var express = require('express');

 var sql = require('mssql');

 var http = require('http');




 var app = express();

 var port = process.env.PORT || 8000;




 var connection = new sql.Connection(webconfig, function(err) {

var request = new sql.Request(connection); 

request.query('select * from Users', function(err, recordset) {

   if(err)      // ... error checks 

        console.log('Database connection error');



console.dir("User Data: "+recordset);

});

 });


  app.listen(port);

  console.log(port+' is the magic port');

或访问这里https://nodejsbeginersprograms.blogspot.in/2017/02/nodejs-basic-tutorial-with-mssql.html

于 2017-02-19T13:57:30.020 回答