Skip to content

Transaction name too long for MSSQL #3950

Closed

Description

@cdm6a

I'm attempting to persist some records within a transaction to a MSSQL database and I'm coming across the following error:

SequelizeDatabaseError: The identifier that starts with '1e340e20-26a3-4881-ac71-1326b01f5af4-savepoint-1' is too long. Maximum length is 32.

This appears to be because per the MSSQL spec (https://msdn.microsoft.com/en-us/library/ms188929.aspx):

transaction_name
Is the name assigned to the transaction. transaction_name must conform to the rules for identifiers, but identifiers longer than 32 characters are not allowed. Use transaction names only on the outermost pair of nested BEGIN...COMMIT or BEGIN...ROLLBACK statements. transaction_name is always case sensitive, even when the instance of SQL Server is not case sensitive.

The transaction name originally appears to be a generated uuid but gets the 'savepoint' text appended to it at:
https://github.com/sequelize/sequelize/blob/2.0/lib/transaction.js#L23

I'm not familiar with other character limits on transaction names in databases but the same code works as intended on Postgres.

I'm using v2.0.0 of Sequelize. Thanks in advance.

Activity

  1. added
    type: bug
    dialect: mssql
    on Jun 17, 2015
  2. sathishsoundharajan commented on Jul 13, 2015

    @sathishsoundharajan

    Hi Any one working on this issue, me too facing the same.
    Please update me.

  3. mickhansen commented on Jul 13, 2015

    @mickhansen
    Contributor

    @mbroadst who sort-of maintains MSSQL is very busy i believe, so unless volunteers provide pull requests no work is being done.

  4. sathishsoundharajan commented on Jul 13, 2015

    @sathishsoundharajan

    @mickhansen Thanks for the update. i dunno what to do, i kind of implemented most of database operation using sequelizejs. is there work around for this.

  5. mickhansen commented on Jul 13, 2015

    @mickhansen
    Contributor

    No idea, i have no MSSQL experience.
    You are welcome to fork and provide a PR that uses another strategy for transaction naming.

  6. mbroadst commented on Jul 13, 2015

    @mbroadst
    Contributor

    @bboysathish I unfortunately don't have time to implement this, but as @mickhansen has stated you can certainly try to tackle it yourself. TBH, transactions were never really supported with the MSSQL dialect for sequelize though they do work for more basic cases, you will run into tons of locking issues with anything approaching a complicated schema.

    AFAICT, the fix for your problem might be as simple as manually naming all your transactions, rather than using one generated by sequelize.

  7. sathishsoundharajan commented on Jul 13, 2015

    @sathishsoundharajan

    @mbroadst Can i pass cls option? As mentioned here http://docs.sequelizejs.com/en/latest/docs/transactions/.
    The problem is transaction is working once, not working on another.

    • How to pass transaction name manually to sequelize?
    • Do i need to fork the repo, implement that logic or it does support it?
  8. mickhansen commented on Jul 13, 2015

    @mickhansen
    Contributor

    You can likely overwrite transaction.id and transaction.name.

  9. sathishsoundharajan commented on Jul 13, 2015

    @sathishsoundharajan

    Please correct me, so i can overwrite transaction id and name like this,

    sequelize
            .transaction({id:randomNumber(),name:randomName()})
    

    is it mentioned anywhere in the docs?

  10. mickhansen commented on Jul 13, 2015

    @mickhansen
    Contributor

    No afraid not, you have to overwrite the props on the transaction object you receive from sequelize.transaction().

    Not mentioned anywhere in the docs cause it's not official API, it's a workaround hack suggestion: https://github.com/sequelize/sequelize/blob/master/lib/transaction.js

  11. sathishsoundharajan commented on Jul 13, 2015

    @sathishsoundharajan

    @mickhansen will try this out. Thanks for the suggestion. :)

  12. mbroadst commented on Jul 13, 2015

    @mbroadst
    Contributor

    @mickhansen I think he can indeed just do:

    sequelize.transaction({ transaction: { id: 'someId' } });
    

    Or am I misreading the source?

  13. mickhansen commented on Jul 13, 2015

    @mickhansen
    Contributor

    @mbroadst ah, that might work, but it might infer since it leads it to believe it's a the child of another transaction.

  14. mbroadst commented on Jul 13, 2015

    @mbroadst
    Contributor

    @bboysathish @cdmcnamara incidentally, @mickhansen has pointed you exactly to where you would want to change this behavior for MSSQL: https://github.com/sequelize/sequelize/blob/master/lib/transaction.js#L26

    What happens there is that, in the absence of an existing transaction id, we generate a uuid.v4() which is too long for the MSSQL spec. An immediate solution would be to change that line to check the current dialect and use if it's MSSQL. A better solution would be to add a function to the AbstractDialect, e.g. generateTransactionId, which by default would just return a uuid.v4() and be overloaded for something unique and useful for MSSQL.

  15. 8 remaining items

  16. Vishal-Isharani commented on May 24, 2016

    @Vishal-Isharani

    @janmeier
    I am bit confuse with @mickhansen 's comment "That error is unrelated to transaction naming."

    I am moving forward with solution provided by @mbroadst

  17. mickhansen commented on May 24, 2016

    @mickhansen
    Contributor

    @Vishal-Isharani Look at the comment i'm referring to, the error he's describing there doesn't appear to have anything to do with this issue.

  18. govi2010 commented on May 24, 2016

    @govi2010

    @manchicken Sorry my mistake, I did not see you were replying to bboysathish . I will implement that and get back to you

  19. govi2010 commented on May 24, 2016

    @govi2010

    @mickhansen and @janmeier here it comes.
    GHLabs@4466dcb

    This fix is working for my database.

    Thank you for your help.
    Let me know if i am doing anything wrong.

    if there is anything else in which you need resource we would like to contribute.

    Regards
    GHLABS IT SOLUTIONS

  20. mickhansen commented on May 24, 2016

    @mickhansen
    Contributor

    @govi2010 Please don't change the whitespace, makes the commit impossible to read, please also remove stuff like debugger statements or logging.

    After that please open a pull request!

  21. govi2010 commented on May 25, 2016

    @govi2010

    @mickhansen we are new to this github so went to pull request on this repository but then i am blank ...

  22. mickhansen commented on May 25, 2016

    @mickhansen
    Contributor

    @govi2010 fork sequelize, branch fork, commit & push changes to branch then there should be a PR button on the main sequelize branch.

  23. added a commit that references this issue on Jun 21, 2016
  24. sheeput commented on Oct 18, 2016

    @sheeput

    Just curious if anyone is working on this issue? I am currently experiencing the same issue. It looks like it was solved, but not finished?

    Thanks.

  25. govi2010 commented on Oct 19, 2016

    @govi2010

    Yes. There are small changes needed but never accepted my pull request.

    On Wed, Oct 19, 2016 at 2:55 AM, sheeput [email protected] wrote:

    Just curious if anyone is working on this issue? I am currently
    experiencing the same issue. It looks like it was solved, but not finished?

    Thanks.

    —
    You are receiving this because you were mentioned.
    Reply to this email directly, view it on GitHub
    #3950 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AIXpX_CQtWpcWkted19bXlwcley-g32xks5q1Tk0gaJpZM4FE52o
    .

    Contact# : 9426442084
    Skype : govinda.alwani
    Thank you
    with best regards.

  26. felixfbecker commented on Oct 19, 2016

    @felixfbecker
    Contributor

    @govi2010 could you link that pull request please? If it was not accepted there is probably a reason for it 😉

  27. govi2010 commented on Oct 19, 2016

    @govi2010

    @felixfbecker i think problem was coding standered liske spaces and etc....

    GHLabs@4466dcb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mssqltype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions