-
Notifications
You must be signed in to change notification settings - Fork 107
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
SQL Server error messages do not always lead to errors in R #745
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
I think the complicated thing here is that the SQL is actually multiple SQL statements and it looks like while we're processing each statement in turn we (a) don't stop after the first error and (b) don't report any error unless it's the first. |
Ah, I'm wrong here. Thanks. |
I think it does stop after the first error. The last insert is not executed:
We first noticed this issue (of errors not being raised from R) with calls to |
Ah, so the problem is just that the error isn't rethrown. That's at least something. |
Slightly more realistic example, in which a trigger contains multiple statements. The throw does lead to inserts being blocked/rolled back (as it should) but, again, the message is not rethrown. On the database (using create database db
use db
create table tbl (col1 int)
create trigger trg on tbl after insert as
begin select 3; if 4 < (select count(*) from tbl) throw 60000, 'error from trigger', 1 end In R: con <- DBI::dbConnect(odbc::odbc(), driver = "odbc driver 17 for sql server", server = "localhost", uid = "sa", pwd = "abCD,.()", trustservercertificate = 'yes')
DBI::dbExecute(con, "use db")
DBI::dbAppendTable(con, "tbl", data.frame(col1 = 1:10)) # no error is raised
DBI::dbReadTable(con, "tbl")
# [1] col1
# <0 rows> (or 0-length row.names) |
The same problem occurs when using ODBC Driver 18. con18 <- DBI::dbConnect(odbc::odbc(), driver = "odbc driver 18 for sql server", server = "localhost", uid = "sa", pwd = "abCD,.()", trustservercertificate = 'yes')
DBI::dbExecute(con18, "select 1; throw 60000, 'something went wrong', 1")
# [1] 0 |
Issue Description and Expected Result
dbExecute()
and similar commands (likedbGetQuery()
,dbWriteTable()
) do not always raise an error when athrow
orraiserror
occurs in SQL Server.Database
Tested with SQL Server 2019, ODBC Driver 17. The reprex that follows uses SQL Server Express, but I also tested using a localdb instance and a production SQL Server database at work.
Reproducible Example
Run a SQL Server Express server locally using docker:
The text was updated successfully, but these errors were encountered: