r-dbi/DBI

Possible bug when executing stored procedure which returns inserted values from procedure in SQL Server?

Closed this issue · 2 comments

I have run into an issue that I can't seem to find a solution to and am wondering if this is a bug or if someone might know what's going wrong here.

In a nutshell, I have a stored procedure in MS SQL Server that executes an insert statement and retrieves the inserted values and returns the result. The stored procedure works perfectly when executed in SQL Server, but I get an error when executed in R. I have cross-posted this question on Stack Overflow. The problem I'm experiencing is described there completely:

https://stackoverflow.com/questions/64578664/error-in-result-fetchresptr-n-nanodbc-nanodbc-cpp2695-24000-microsoft

Does anyone have any ideas of why I'm not getting the expected data? I saw this note in the documentation so I'm wondering if the way this is being handled clears my results before they are returned to R?:

Returns the result of a query as a data frame. dbGetQuery() comes with a default implementation (which should work with most backends) that calls dbSendQuery(), then dbFetch(), ensuring that the result is always free-d by dbClearResult().

So a comment on Stack Overflow solved this problem for me. It appears that I simply needed to add SET NOCOUNT ON to the stored procedure in SQL Server. I'm closing this issue. Thanks and sorry for the trouble.

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.