none
TSql130Parser does not recognize hints RRS feed

  • Question

  • I created the following console application with a reference to Microsoft.SqlServer.TransactSql.ScriptDom.dll: 
    Imports Microsoft.SqlServer.TransactSql.ScriptDom
    Imports System.IO
    
    Module Module1
        Sub Main()
            Dim sql = "SELECT * FROM Product OPTION(USE HINT('ENABLE_PARALLEL_PLAN_PREFERENCE'))"
            Dim parser As New TSql130Parser(False)
            Dim errors As Collections.Generic.IList(Of ParseError)
            Dim script As TSqlScript = parser.Parse(New StringReader(sql), errors)
            Console.WriteLine(errors(0).Message)
            Console.ReadKey()
        End Sub
    End Module
    Running this console application produces the following output:

        Incorrect syntax near HINT.

    But this SQL fragment is correctly parsed in Microsoft SQL Server Management Studio.

    It seems therefore, that TSql130Parser does not work correctly. 
    Do you know if there is a fix for this?
    Friday, January 25, 2019 8:40 AM

All replies

  • That query hint was first intorduced in 20016 SP 1 CU2 https://www.brentozar.com/archive/2017/05/breaking-sql-server-2016-sp1-cu2-supports-enable_parallel_plan_preference-hint/

    You have to install a newer SqlDom Version, e.g. from Microsoft® SQL Server® 2016 Service Pack 2 Feature Pack


    Olaf Helper

    [ Blog] [ Xing] [ MVP]


    • Edited by Olaf HelperMVP Friday, January 25, 2019 9:17 AM
    • Proposed as answer by Puzzle_Chen Monday, January 28, 2019 8:04 AM
    Friday, January 25, 2019 9:16 AM
  • Hi pappasa,

    Have you solved your problem? Please check the fix posted by Olaf.

    If you have resolved your issue, please close the thread by marking the useful reply as answer. It will be easier for other community members to find the useful ones.

    Thanks for your contribution.

    Best Regards,
    Puzzle
    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, January 28, 2019 8:05 AM
  • You write when this feature was introduced, but not if there is a fix for Microsoft.SqlServer.TransactSql.ScriptDom.TSql130Parser.
    Monday, January 28, 2019 9:16 AM
  • The above post writes when this feature was introduced, but not if there is a fix for Microsoft.SqlServer.TransactSql.ScriptDom.TSql130Parser.
    Monday, January 28, 2019 9:17 AM
  • Hi pappasa,

    Which version of SQL Server are you using? Check it by running SELECT @@version in SSMS and you can install the fix you need from SQL Server 2016 build versions. Like Olaf said, you will need at least SQL Server 2016 SP1 CU2 to use this. And it is always recommended to install the latest Service Pack for SQL Server.


    Best Regards,
    Puzzle
    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, January 28, 2019 9:30 AM
  • What for a fix? You can not expect that an older SqlDom knwos what may for Feature will be introduced in newer SQL Server Version.

    Install & use the most latest SqlDom version.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Monday, January 28, 2019 9:35 AM
  • I get the same error on my SQL Server 2016 instance. 


    After I installed SQL Server 2016 Service Pack 2 (SP2), it works fine.


    Best Regards,
    Puzzle
    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, January 28, 2019 10:01 AM
  • The above post writes when this feature was introduced, but not if there is a fix for Microsoft.SqlServer.TransactSql.ScriptDom.TSql130Parser.
    You can use the 14.0 version or later of Microsoft.SqlServer.TransactSql.ScriptDom.dll in order for theTSql130Parser to recognize the newer hint. The latest 14.0 version is 14.0.3811.1 as of this writing and is available as a NuGet package (https://www.nuget.org/packages/Microsoft.SqlServer.DacFx.x64/140.3881.1). There is also a 15.0  version available (https://www.nuget.org/packages/Microsoft.SqlServer.DacFx.x64/150.4200.1), which supports SQL Server 2019 (currently in CTP) and the older TSqlParsers with the latest features.

    Dan Guzman, Data Platform MVP, http://www.dbdelta.com

    Monday, January 28, 2019 12:02 PM