1
votes

I'm running different r programs on the linux server. Programs fail due database connectivity giving following errors:-

1: In odbcDriverConnect(paste0("DRIVER={SQL Server}; server=", server, : [RODBC] ERROR: state 08001, code 0, message [unixODBC][FreeTDS][SQL Server]Unable to connect to data source

2: In odbcDriverConnect(paste0("DRIVER={SQL Server}; server=", server, : [RODBC] ERROR: state 01000, code 20002, message [unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed

3: In odbcDriverConnect(paste0("DRIVER={SQL Server}; server=", server, : [RODBC] ERROR: state 01000, code 20017, message [unixODBC][FreeTDS][SQL Server]Unexpected EOF from the server

4: In odbcDriverConnect(paste0("DRIVER={SQL Server}; server=", server, : ODBC connection failed Execution halted

Sometimes, programs run completely without giving any error. Sometimes it fails. I'm not able to figure out exactly what the problem is.

I tested a piece of code to see how it's behaving:

library(RODBC)

library(RODBCext)



for (i in 1:100){

  dbhandle <- odbcDriverConnect(paste0("DRIVER={SQL Server}; server=",server,"; database=",dbname,"; uid=",username,"; pwd=",password, "; TDS_Version=8.0; Port=1433;", sep=""))

  query <- "select * from analysis"

  analysis <- sqlExecute(dbhandle, query = query, fetch = T)

  odbcClose(dbhandle)


} 

Sometimes it's getting executed completely. Sometimes it fails in between(for example it failed 45th time connecting to database)

I never faced this problem in windows environment.

I want to know what exactly is the problem in this case. Is it something related to network, driver, my connection string or database.

And what could be the solution to this problem.

1
@NeerajKumar, updated TDS version in odbc.inst.ini. But, it didn't help.sm925
@NeerajKumar, updated odbc.ini and freetds.conf too. Still giving that error.sm925
could you share TDS.conf file?Neeraj Kumar
You mean freetds.conf?sm925

1 Answers

0
votes

I guess my connection string and config file looks good.

Maybe there was a network issue which was dropping an open RODBC connection.

I tried this solution:-

 repeat
        {
          dbhandle <- odbcDriverConnect(paste0("DRIVER={SQL Server}; server=",server,"; database=",dbname,"; uid=",usernm,"; pwd=",passwd, "; TDS_Version=8.0; Port=1433;", sep=""))
          if(class(dbhandle) == "RODBC"){
              break
            }
        }

With this I'm not proceeding till my dbhandle is of class RODBC.

By integrating this code in my program wherever database connection was required, I was able to run programs without getting those error messages.