I am trying to use TVP with tedious and keep getting this error while using a DateTime
parameter.
The exception while building the request is :
days = Math.floor((parameter.value.getTime() - UTC_EPOCH_DATE.getTime()) /
(1000 * 60 * 60 * 24));
^
Exception:
TypeError: parameter.value.getTime is not a function
The code looks like this
/*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
Looking at the tedious code for data-types.js I found that the parameter.value
was a string and not an object .
Not sure what am I doing wrong here.
What I tried
- without
datetime
- works - with
DateTime2
- the incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 2 (""): Data type 0x03 is unknown. - With https://github.com/patriksimek/node-mssql, but internally it again uses Tedious