My node app is crashing when node-mssql executes a stored procedure with a TVP parameter that violates its type's primary key constraint.
events.js:183
throw er; // Unhandled 'error' event
^
Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]The data for
the table-valued parameter 1 doesn't conform to the table type of the
parameter. SQL Server error is: 3602, state: 30
I've tried handling the error in a number of ways including adding event listeners. I suspect I'm using them incorrectly but haven't managed to figure out exactly how.
const sql = require('mssql/msnodesqlv8');
sql.on('error', err => {
console.log(err);
})
const tvp = new sql.Table('EventsMultiplicativeType');
tvp.columns.add('MUID', sql.Int);
tvp.columns.add('DateID_Start', sql.Int);
tvp.columns.add('Value', sql.Float);
tvp.columns.add('Number_Consecutive_Observation', sql.Int);
tvp.columns.add('Detail', sql.VarChar(sql.MAX));
tvp.rows.add(8750, 20180101, 5, 5, 'Hello');
tvp.rows.add(8750, 20180101, 5, 5, 'Hello');
sql.connect(dbConfig).then(pool => {
pool.on('error', err=> console.log(err));
return pool.request()
.on('error', err => console.log(err))
.input('EventTable', tvp)
.execute('sp_ValidateEventsMultiplicative')
.then(result =>console.log(results))
.catch(err => console.log(err))
}).catch(err => console.log(err));
sql.on('error', err => {
console.log(err);
})