RODBC : Single Backslash in server name [closed]

2019-08-16 04:26发布

I have the following issue : the SQL server I am trying to connect to using RODBC has a backslash in it.

Here is my code:

library(RODBC)
server <- "servername\REP"
database<- "databasename"
connectionString <- paste("Driver={SQL Server};server=",server,";database=",database,";trusted_connection=yes;")
channel <-  odbcDriverConnect(connection=connectionString)

Of course \R causes an issue and the channel cannot be opened. One solution would be to escape the backslash:

   server <- "servername\\REP"

But then the server name is not the right one anymore and the connection cannot be made.

Basically I am stuck needing server <- "servername\REP" to work!

Surely someone has already encountered this issue...

1条回答
该账号已被封号
2楼-- · 2019-08-16 05:08

Ok so the solution here was using "paste0" to generate the connection string :

library(RODBC)
server <- "servername\REP"
database<- "databasename"
connectionString <- paste0("Driver={SQL Server};server=",server,";database=",database,";trusted_connection=yes;")
channel <-  odbcDriverConnect(connection=connectionString)

using "paste()" was adding pesky white spaces.

查看更多
登录 后发表回答