-
Notifications
You must be signed in to change notification settings - Fork 281
Fix for stored procedure empty cell bug #2887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
… dev/gribeiro/emptyCellBug
There was a problem hiding this 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.
Co-authored-by: RubenCerna2079 <[email protected]>
…data-api-builder into dev/gribeiro/emptyCellBug
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 6 pipeline(s). |
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?
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
Before the changes:

If we try to run a stored procedure that reads that empty cell, we get an error
After changes

Stored procedure runs as expected