Issue with SQL Server compatibility level 2022 and sp_executesql

Eckels, Adam 0 Reputation points
2024-07-19T20:07:28.8033333+00:00

One of our customers running SQL standard edition 2022 wanted to explore setting their database's compatibility level to 2022; but when they do this, at least one of our queries fails to return metadata. So they have to keep the compatibility level at 2019 to avoid the problem. The SQL looks like this:

------------------- start SQL:

exec sp_executesql 

N' SET FMTONLY OFF; SET NO_BROWSETABLE ON; SET FMTONLY ON;

select (some columns) from (a table) 

where PropertyId=@propertyid and TransKey=@transkey and TransSrc=@transsrc',

N'@propertyid varchar(3), @transkey varchar(6), @transsrc varchar(7)',

@propertyid='001', @transkey='2222.2', @transsrc='XMLTest'

-------------------end of SQL

When troubleshooting in SSMS [at compatibility level 2022], we're getting a response of "Commands completed successfully." (along with the completion time); but no columns (column headers) appear like they normally would.

Here's the weird part:

Then when we change the @transkey parameter's type to nvarchar, it works - even though the column's type is varchar. It also works if we set the other two parameters' types to nvarchar and keep the @transkey parameter's type as varchar. Except for the select statement, the SQL is auto-generated by a .NET Framework 4.8 DataTable object. What the heck is going on here? Thanks for your help!

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,598 questions
{count} votes

3 answers

Sort by: Most helpful
  1. LucyChenMSFT-4874 4,090 Reputation points
    2024-07-22T06:06:28.47+00:00

    Hi @Eckels, Adam,

    Thank you for reaching out and welcome to Microsoft Q&A!

    Please refer to this article, we can get the information below:

    User's image

    Best regards,

    Lucy Chen


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    https://docs.microsoft.com/en-us/answers/support/email-notifications


  2. Eckels, Adam 0 Reputation points
    2024-07-24T22:10:40.8033333+00:00

    The cumulative update released just yesterday resolved the issue.
    https://www.microsoft.com/en-us/download/details.aspx?id=105013


  3. Eckels, Adam 0 Reputation points
    2024-07-24T22:14:15.75+00:00

    The cumulative update released just yesterday resolved the issue:

    https://www.microsoft.com/en-us/download/details.aspx?id=105013

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.