I'm using DBI::dbWriteTable
to upload a table with ~11M rows to a database in Azure SQL.
However, I keep running into the following error:
Error in result_insert_dataframe(rs@ptr, values, batch_rows) :
nanodbc/nanodbc.cpp:1752: 08S01: [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: An existing connection was forcibly closed by the remote host.
[Microsoft][ODBC Driver 18 for SQL Server]Communication link failure
I've tried pushing the data by slicing it into smaller subsets like so:
row_slices <- seq(1, nrow(bseg_output_data), by = 100000)
con <- connect_azure_sql()
dbWriteTable(conn = con,
name = "behavioural_segmentation_data",
value = bseg_output_data %>% slice(1:row_slices[2]),
overwrite = TRUE)
dbDisconnect(con)
for(i in 2:length(row_slices)) {
con <- connect_azure_sql()
print(i)
dbWriteTable(conn = con,
name = "behavioural_segmentation_data",
value = bseg_output_data %>% slice(i:row_slices[i+1]),
append = TRUE)
dbDisconnect(con)
}
(I think there's some faulty logic with the row_slices[i+1]
part but ignore that.)
When I do it this way, i
gets up to about 4 but the same error occurs. I kept opening and closing the connection inside the for loop hoping that that might solve the issue. But really just fumbling about in the dark here.
Is there something that I'm doing wrong, or a better way to upload a large table to an SQL database?
Any help would be appreciated!