0

I got a website with a form full of settings where each of the inputs save a value in a MS SQL Database.

But when i set a field to '' i got the following error message: "The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 3 (""): Data type 0x00 is unknown."

My node.js service calls a stored procedure which looks like this:

CREATE PROCEDURE [dbo].[ckd_Configurations_Update]
@Key NVARCHAR(256),
@Value NVARCHAR(MAX)
AS
BEGIN
  UPDATE [dbo].[ckd_Configurations] SET [Value]=@Value WHERE [Key]=@Key;
END

My table:

CREATE TABLE [dbo].[ckd_Configurations]
(
    [Key] NVARCHAR(256) NOT NULL PRIMARY KEY,
    [Value] NVARCHAR(MAX)
)

And finally my node.js route to set the configurations:

router.post('/configurations/update', function (req, res) {
    var request = new sql.Request(databaseConnection);
    var configuration = req.body;
    request.input('Key', sql.NVarChar(256), configuration.Key);
    request.input('Value', sql.NVarChar(sql.MAX), configuration.Value);

    request.execute('ckd_Configurations_Update', function (error, recordsets) {
        if (error) {
            res.json(new apiResponse(false, error.message));
        } else {
            res.json(new apiResponse(true, '', recordsets[0]));
        }
    });
});
Michael Malura
  • 1,131
  • 2
  • 13
  • 30

2 Answers2

1

Just update mssql to 2.0. The issue was fixed in this release.

Patrik Šimek
  • 1,038
  • 10
  • 14
0

If I understand your question correctly, you want to be able to insert empty string in the database?

ALLOW 'NULL' in Table against Value column. So that null value can be set to it. In the stored procedure, put a condition :

IF @Value = ''
BEGIN
    SET @Value = NULL
END

When you want to return the value as empty string, you can use this in the SELECT statement.

Select isnull(Value, '') as Value from [ckd_Configurations]

Set a dummy value to the field as '-1' and then check that in your stored procedure and set it to NULL. I think the problem here is that your service is not accepting the empty string which is causing the problem. In the stored procedure, you can also set the

@Value NVARCHAR(MAX) = NULL
Sorrel Vesper
  • 414
  • 4
  • 18
  • Some of these settings are optional. So i want to 'clear' them. To do this i delete everything in the input field. When i press 'save' i get the error message from above. That's what i mean with 'insert empty string'. – Michael Malura Feb 18 '15 at 07:52
  • I see. Your problem is when you're sending the input to the database, then you get this error? Let me edit my answer! – Sorrel Vesper Feb 18 '15 at 07:54