Sf package st_read function returns "the file doesn't seem to exist" when attempting to import sql server geospatial table

I am attempting to import a SQL Server geospatial table using sf package's st_read function, as follows:

dsn <- "driver={SQL Server};server=gdb;database=mydata;trusted_connection=true"
myPolygons <- st_read(dsn=dsn, query=paste0("SELECT * FROM mytable")

This throws the following:

Error: Cannot open "driver={SQL Server};server=gdb;database=mydata;trusted_connection=true";
The file doesnt seem to exist.

This worked fine a few weeks ago and now it has suddenly stopped working. It fails with all of the spatial tables in my SQL Server database. I'm sorry I don't know how I can provide a reprex, since the problem is with importing from a secured SQL Server.

I'm pretty sure the dsn string is fine, because it works with the RODBC package to import non-spatial data. The st_read function works fine when importing an ESRI shapefile. The error occurs only when trying to import a sql server geospatial table. I'm certain that the tables I'm trying to import have appropriate geometry columns.

I tried removing any packages I thought might conflict with sf, then reinstalled sf, but still getting the same error.

I'm totally baffled why this is suddenly failing, and the error message "file doesn't exist" doesn't provide me with any clues. Any help would be most appreciated.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.