乏味的 SQL Server TVP:parameter.value.getTime 不是日期时间的函数

Raj*_*jee 3 sql-server node.js node-mssql tedious

我正在尝试乏味地使用 TVP 并在使用DateTime参数时不断收到此错误。

构建请求时的异常是:

 days = Math.floor((parameter.value.getTime() - UTC_EPOCH_DATE.getTime()) /
 (1000 * 60 * 60 * 24));
                                             ^
Run Code Online (Sandbox Code Playgroud)

例外:

类型错误:parameter.value.getTime 不是函数

代码看起来像这样

/*declare table*/``    
let table = {
        columns: [
            { name: 'a', type: TYPES.VarChar, length: 50, nullable: true },
            { name: 'b', type: TYPES.Int},
            { name: 'c', type: TYPES.DateTime}

        ],
        rows: [
           ['hello tvp', 777,'05/08/07 12:35 PM'],
           ['OLO', 45,'05/08/16 1:30 AM']
        ]
    };

/*request code*/
var request = new Request("MyCustomStoredProcedure", function (err, rowCount) {
                    if (!err) {
                        callback(err)
                        logger.info("rowCount", rowCount)
                    } else {
                        callback(rowCount)
                        logger.error("Error => ", err)
                    }
                });
                request.addParameter('tvp', TYPES.TVP, table);

                request.on('row', function (columns) {
                     logger.info("data", columns)
                });

                connection.callProcedure(request);



CREATE TYPE TestType AS TABLE (a VARCHAR(50), b INT, c DateTime);

CREATE PROCEDURE MyCustomStoredProcedure 
    (@tvp TestType readonly) 
AS 
    SELECT * 
    FROM @tvp
Run Code Online (Sandbox Code Playgroud)

查看 data-types.js 的乏味代码,我发现它parameter.value是一个 string 而不是 object 。

不知道我在这里做错了什么。

我试过的

  • 没有datetime- 作品
  • with DateTime2- 传入的表格数据流 (TDS) 远程过程调用 (RPC) 协议流不正确。参数 2 (""):数据类型 0x03 未知。
  • 使用https://github.com/patriksimek/node-mssql,但在内部它再次使用乏味

Raj*_*jee 5

我使用了 Varchar,而不是 DateTime,它解决了我的问题。我知道这不是最好的解决方案,但为了节省时间,我接受了它。