运行带有NodeJS和MSSQL程序包错误的存储过程 [英] Running a stored procedure with NodeJS and MSSQL package error

查看:193
本文介绍了运行带有NodeJS和MSSQL程序包错误的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取MSSQL nodejs包,以使用以下代码从Microsoft SQL Server返回存储过程的结果.但是我得到的错误是...

Im trying to get the MSSQL nodejs package to return the results of a stored procedure from Microsoft SQL server using the code below. However the error I get is...

[TypeError: Cannot read property 'type' of undefined]

我不确定我是否正确地完成了输入,因为我找不到在线上有多个输入的示例.

I'm not sure I have done the inputs correctly as I couldn't find an example with more than one input anywhere online.

有什么想法吗?

exports.executeSqlStoredProd = function (callback) {
    var conn = new sqlDb.Connection(settings.dbConfig)
    conn.connect().then(function () { 
        var req = new sqlDb.Request(conn);
        req.input('ProductEntryID', req.Int, 3299);
        req.input('LoginEntryID', req.Int, 4);
        req.input('TempLoginEntryId', req.Int, -1);
        req.input('AddToWishList', req.Bit, 0);
        req.input('WebPortalId', req.Int, 0);
        req.execute('J_ViewAProduct').then(function(err, recordsets) {
        console.log(recordsets);
        callback(recordsets)
    })}).catch(function(err){ 
        console.log(err);
        callback(null, err);
    });
}

我使用"Seriate"包成功完成了请求,但更喜欢使用mssql.适用于"Seriate"的代码如下.

I did the request sucessfully using the package "Seriate" but would prefer to use mssql. The code that worked for "Seriate" is below.

exports.getVAP = function(req, resp, pid) {  
    sql.execute({
        procedure: "J_ViewAProduct",
        params: {
            ProductEntryID: {
                type: sql.INT,
                val: pid
            },
            LoginEntryID: {
                type: sql.Int,
                val: 4
            },
            TempLoginEntryId: {
                type: sql.Int,
                val: -1
            },
            AddToWishList: {
                type: sql.Bit,
                val: 0
            },
            WebPortalId: {
                type: sql.Int,
                val: 0
            }
        }
    }).then(function(results){
        console.log(results)
        httpMsgs.sendJSON(req, resp, results)
        //httpMsgs.sendJSON(req, resp, results[0])
        resp.end();
    }), function(err){
        httpMsgs.show500(req, resp, err)
    }

};

推荐答案

我认为这条线是

req.input('ProductEntryID', req.Int, 3299);
req.input('LoginEntryID', req.Int, 4);
req.input('TempLoginEntryId', req.Int, -1);
req.input('AddToWishList', req.Bit, 0);
req.input('WebPortalId', req.Int, 0);

其中req.input似乎是错误的.

which has req.input thats wrong it seems.

请尝试使用此代码

var sql = require('mssql');

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

var getCities = function() {
  var conn = new sql.Connection(config);
  conn.connect().then(function(conn) {
    var request = new sql.Request(conn);
    request.input('City', sql.VarChar(30), 'Cbe');
    request.input('NameNew', sql.VarChar(30), 'Cbe');
    request.execute('spTest').then(function(err, recordsets, returnValue, affected) {
      console.dir(recordsets);
      console.dir(err);
    }).catch(function(err) {
      console.log(err);
    });
  });
}

getCities();

我自己尝试了一下,并给出了结果.

I tried this myself and its giving the results.

这篇关于运行带有NodeJS和MSSQL程序包错误的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆