Skip to content

Conversation

gilemos
Copy link
Contributor

@gilemos gilemos commented Sep 25, 2025

Why make this change?

We have recently noticed that, if we have a column of type NVARCHAR or VARCHAR and we try to run a stored procedure that reads a row in which that column has an empty string value, we had an internal server error.

This error happens when we try to run the method GetChars passing in a buffer with length 0

This PR aims to fix this problem

What is this change?

We have added a small change to the method that was throwing the exception.
If we find that resultFieldSize is 0 - which means that the data in the cell we are reading has a length of 0 - we will not call the method GetChars to read the data, but assume the data is empty and return the size of the data read in bytes as 0.

As you can see in the example bellow, that fixes the issue.

How was this tested?

  • Integration Tests
  • Unit Tests

Sample Request(s)

We have a table with a column of type NVARCHAR called "Description". In one of the rows, Description is an empty string

image

Before the changes:
If we try to run a stored procedure that reads that empty cell, we get an error
image

After changes
Stored procedure runs as expected
image

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where attempting to read empty string values from NVARCHAR or VARCHAR columns in stored procedures was causing internal server errors. The issue occurred when the GetChars method was called with a zero-length buffer.

  • Adds early return for empty cells to prevent GetChars method calls with zero-length buffers
  • Prevents internal server errors when reading empty string values from database columns

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@gilemos gilemos changed the title fixes empty cell bug Fixe for stored procedure empty cell bug Sep 25, 2025
@gilemos gilemos changed the title Fixe for stored procedure empty cell bug Fix for stored procedure empty cell bug Sep 26, 2025
Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix, left a few suggestions.

@gilemos
Copy link
Contributor Author

gilemos commented Oct 8, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 8, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 8, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 9, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 9, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 9, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 9, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 9, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@gilemos
Copy link
Contributor Author

gilemos commented Oct 10, 2025

/azp run

Copy link

Azure Pipelines successfully started running 6 pipeline(s).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants