My problem is the following: I am using R language with RODBC library and I am trying to get a connection with a database, which its name contain non English character. In this case I wanted to establish a connection with a database with Czech republic alphabet, but in the future could be Chinese, Russian, etc.
Here is my code:
library(RODBC)
con <- odbcDriverConnect("driver={ODBC Driver 17 for SQL Server};server=<server_name>;trusted_connection=yes;database=<database_name_with_č_character>", DBMSencoding="UTF-8")
The error I get is:
Warning messages:
1: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server};server=<server_name>;trusted_connection=yes;database=<database_name_with_č_character>", :
[RODBC] ERROR: state 28000, code 18456, message [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user '<my_user>'.
2: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server};server=<server_name>;trusted_connection=yes;database=<database_name_with_č_character>", :
[RODBC] ERROR: state 42000, code 4060, message [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot open database "<database_name_with_č_character>" requested by the login. The login failed.
3: In odbcDriverConnect("driver={ODBC Driver 17 for SQL Server};server=<server_name>;trusted_connection=yes;database=<database_name_with_č_character>", :
ODBC connection failed
I also tried to use a DSN connection that it works, but when I want to use the database with the non English character... I cannot.
con <- odbcConnect("dev_server", DBMSencoding="UTF-8")
dbName <- "<database_name_with_č_character>"
query <- paste("select top 1 * from [", dbName, "].<schema>.<table> ", sep="")
exitStatus <- sqlQuery(con, query, errors=T, as.is=T)
The error:
[1] "42S02 208 [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name '<database_name_with_č_character>..'"
[2] "[RODBC] ERROR: Could not SQLExecDirect 'select top 1 * from <database_name_with_č_character>..'"
Note: if I tried the following code with database's name that does not contain non English character the code works.
Software versions:
- R: Microsoft- R Open - R-4.0.2
- Microsoft SQL Server 2017 - 14.0.3381.3 (X64)
- SQL Server running on Windows Server 2016 Standard (10.0)