RODBC connectivity to Oracle without tnsnames.ora

懵懂的女人 提交于 2019-12-07 12:55:07

问题


I am trying to connect to Oracle from R using RODBC without using tnsnanes.ora.

I have tried following strings, but none of them are working.

> con.text <- paste0("Driver={OracleODBC-11g};Dbq=//oracle.server:1527/database.pdw.prod;Uid=user;Pwd=pswd;")

> con.text <- paste0("Driver={OracleODBC-11g}; ",
         "CONNECTSTRING=(DESCRIPTION=(ADDRESS= (PROTOCOL = TCP)(HOST = oracle.server)(PORT = 1527))(CONNECT_DATA=(SERVICE_NAME = database.pdw.prod))); uid=user;pwd=pswd;")

> con.text <- paste0("Driver=", "OracleODBC-11g"
                     , ";Server=", "oracle.server"
                     , ";Database=", "database.pdw.prod"
                     , ";Uid=", "user"
                     , ";Pwd=", "pwd", ";")

> con.text <- paste0("Driver=", "OracleODBC-11g"
                      , ";Server=", "oracle.server"
                      , ";CONNECTSTRING=" , "(DESCRIPTION=(ADDRESS= (PROTOCOL = TCP)(HOST = oracle.server)(PORT = 1527))(CONNECT_DATA=(SERVICE_NAME = database.pdw.prod)))" 
                      , ";Database=", "database.pdw.prod"
                      , ";Uid=", "user"
                      , ";Pwd=", "pswd", ";")
> con1 <- odbcDriverConnect(connection = con.text)

But for all these strings I am getting following error:

Warning messages:
1: In odbcDriverConnect(connection = con.text) :
 [RODBC] ERROR: state HY000, code 12162, message [unixODBC][Oracle][ODBC][Ora]ORA-12162: TNS:net service name is incorrectly specified
2: In odbcDriverConnect(connection = con.text) : ODBC connection failed

OR

      1: In odbcDriverConnect(connection = con.text) :
  [RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified

回答1:


The correct sysntaxis you are looking for is

Conex     <- odbcDriverConnect("DRIVER=Oracle en OraClient11g_home2;UID=USERNAME;PWD=PASSWORD;DBQ=//HOSTNAME:PORT/ORACLE_SID;",
             believeNRows = FALSE)

Ex

Conex     <- odbcDriverConnect("DRIVER=Oracle en OraClient11g_home2;UID=John;PWD=Deere;DBQ=//fcoracleserver.youdomain:1521/TestEnvironment;",
             believeNRows = FALSE)

The hard part is to find the name of the Driver, as you can see mine is on spanish.

What I did is I create first a ODBC Conection using the C:\Windows\System32\odbcad32.exe, there you can check the right name of your Oracle or SQL Server driver.

Once you create the conection, you can use odbcDataSources() on R, to see that conection and to find out the driver. Thats really the hard part.

Hope it helps !



来源:https://stackoverflow.com/questions/37114170/rodbc-connectivity-to-oracle-without-tnsnames-ora

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!