agstudy / rsqlserver

Sql Server driver database interface (DBI) driver for R. This is a DBI-compliant Sql Server driver based on the System.Data.SqlClient.
82 stars 30 forks source link

Error in while (!dbHasCompleted(res)) { : argument is of length zero #31

Open jfontestad opened 7 years ago

jfontestad commented 7 years ago
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
agstudy commented 7 years ago

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)
jfontestad commented 7 years ago

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)) }

agstudy commented 7 years ago

What is con?

jfontestad commented 7 years ago

that's what i was using at the time as my connection variable.