Query to Snowflake database isn't working because no active warehouse is selected

trevin_flick picture trevin_flick · Feb 17, 2020 · Viewed 11.6k times · Source

I'm able to successfully connect to the Snowflake database via R but I'm having trouble getting the data because no active warehouse is selected. Below is the error message:

No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.

Here is my code I'm using.

  con <- DBI::dbConnect(
    odbc::odbc(), 
    UID    = user, 
    PWD    = pass, 
    Server = host,
    Warehouse = 'YOUR_WAREHOUSE_NAME',
    Driver = "SnowflakeDSIIDriver",
    Role = role,
    Database = database,
    Autthenticator = "external browser"
  )

dbGetQuery(con, "SELECT * FROM MY_TABLE LIMIT 100")

I've based my connection and query from this thread on RStudio Community but I'm not having any luck. I've also tried using the 'use warehouse MY_WAREHOUSE' command in my query without any luck.

Note: I can connect successfully and query data via Python so I think this is an R specific issue.

Answer

Coffee and Code picture Coffee and Code · Aug 2, 2020

I ran into this issue too. It's probably not the best answer as I'm just testing some dev code (in python), but I had to issue:

GRANT USAGE ON WAREHOUSE my_warehouse TO ROLE writer_role;

Of which the user I was using to connect to Snowflake is a member of, then I was able to write to the table.