rsqlserver
rsqlserver copied to clipboard
Error in while (!dbHasCompleted(res)) { : argument is of length zero
dbHasCompleted(res)
Error in clrNew("rsqlserver.net.SqlDataHelper", res) :
Type: System.InvalidOperationException
Message: Invalid attempt to call FieldCount when reader is closed.
Method: Int32 get_FieldCount()
Stack trace:
at System.Data.SqlClient.SqlDataReader.get_FieldCount()
at rsqlserver.net.SqlDataHelper..ctor(SqlDataReader reader) in C:\Users\Ruaridh Williamson\Documents\GitHub\rsqlserver\src.nocompile\rsqlserver.net\src\SqlDataHelper.cs:line 68
Ho w do you use it ? can you give more context ? From the error message you are trying to access a closed reader, that means that the connection object is closed.
can you test this code for example:
conn <- get_connection()
dbWriteTable(con, "T_MTCARS", mtcars[1:5, ])
query <- "SELECT * FROM T_MTCARS"
res <- dbSendQuery(conn, query)
df1 <- fetch(res,as.integer(floor(nrow(mtcars)/2)))
dbHasCompleted(res)
Hello, I was just using the default example that is attached with the DBI package.
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4") while(!dbHasCompleted(res)){ chunk <- dbFetch(res, n = 5) print(nrow(chunk)) }
What is con?
that's what i was using at the time as my connection variable.