node-mssql icon indicating copy to clipboard operation
node-mssql copied to clipboard

DeadLock error while saving the data

Open bommojuvishu opened this issue 6 years ago • 4 comments

Actual behaviour:

Getting this issue in prod environment where around 30 users are working and trying to update json data in a table. The table has a page lock and column where we store complete json. Somehow it doesn’t release transaction and gives the deadlock issue when another request comes in which updates json in another row.

Code to create connection object :

var connection = new sql.ConnectionPool(config);
connection.connect();
app.set('con1', connection);

UpdateJsondetails: function (id, data, success, error) {
        try {
            
   con1.request().input('data1', sql.NVarChar('max'), data).input('id', sql.BigInt,id).execute('update_json').then(function (recordSet) {
                success(recordSet);

            }).catch(function (err) {

                console.log(err);

            });
        } catch (e) {
            logger.error(e.message);
            error(e);
        }
    },
SP is

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER     PROCEDURE   [dbo].[update_json]
       -- Add the parameters for the stored procedure here
       @data1 AS nvarchar(max),
          @id  AS bigint
      
AS
BEGIN       
       SET NOCOUNT ON;
         update dataTable set data1=@data1, updated_on= GETDATE() where id=@id 

we are getting the error in the logs as: originalError: { Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Transaction (Process ID 398) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. sqlstate: '40001', code: 1205 },

Software versions

  • NodeJS: 8.11.4
  • node-mssql: 4.1.0
  • msnodesqlv8": 0.6.8
  • SQL Server: Microsoft SQL Server 2016(SP2-GDR) (KB4293802) - 13.0.5081.1 (x64)

bommojuvishu avatar Mar 24 '20 08:03 bommojuvishu

Is this happening in a transaction? if so the transaction would need to be committed or rolled back...

dhensby avatar Apr 02 '20 12:04 dhensby

closing this due to inactivity

dhensby avatar Apr 23 '20 20:04 dhensby

@dhensby i'm having same issue. uploadParams.files.forEach(async (file: Express.Multer.File) => { try { console.log('about to upload'); const blobPath = await uploadBlob( file, uploadParams.folderPath, uploadParams.aco); console.log('uploaded');

    const title = file.originalname.split('.')[0];

    console.log('about to sql');
    const result = await (await pool).request()
      .input('Author', NVarChar, uploadParams.author)
      .input('collectionID', Int, uploadParams.collectionID)
      .input('Owner', Int, uploadParams.owner)
      .input('EntryType', NVarChar, file.mimetype)
      .input('FileSize', BigInt, file.size)
      .input('OriginalFileName', NVarChar, file.originalname)
      .input('Title', NVarChar, title)
      .input('BlobPath', NVarChar, blobPath)
      .input('Container', NVarChar, uploadParams.testContainer)
      .execute('coach.DocRepo_AddEntry');
    console.log('about to sqled');

  } catch (error) {
    // handle error here
    console.error(error);
  }
});

eprokhor avatar Nov 17 '20 04:11 eprokhor

see #1137

dhensby avatar Nov 18 '20 10:11 dhensby