Skip to content

Error creating temporary tables with Microsoft SQL Server connection #438

@lymanmark

Description

@lymanmark

I am getting an error when trying to create temporary tables using compute and copy_to with Microsoft SQL Server connection. As shown below, I can create non-temporary tables.

library(tidyverse)

my_con <-
  DBI::dbConnect(
    odbc::odbc(),
    Driver = "SQL Server",
    Server = ".\\SQLExpress",
    Database = "temp",
    Trusted_Connection = "True"
  )

iris %>% 
  copy_to(my_con, ., "iris")
#> Created a temporary table named: #iris
#> Error in result_insert_dataframe(rs@ptr, values, batch_rows): nanodbc/nanodbc.cpp:1617: 42000: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name '#iris'.  [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.

my_table <- iris %>% 
  copy_to(my_con, ., "iris", temporary = FALSE)

my_table %>% 
  compute()
#> Created a temporary table named: #dbplyr_001
#> Error: nanodbc/nanodbc.cpp:1617: 42S02: [Microsoft][ODBC SQL Server Driver][SQL Server]Table '#dbplyr_001' does not exist. 
#> <SQL> 'UPDATE STATISTICS "#dbplyr_001"'

Created on 2020-04-29 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions