go version go1.8.1 windows/amd64 and I am importing
"github.com/mattn/go-oci8"
"database/sql"
For connecting to my oracle database. Here when I give db username, password, port and table name in connection string
func openAndConnectToDb(sbconfig ConnectorConfig) *sql.DB {
logger := sbgoclient.Log
logger.Println("Open the database")
// oraprop := LoadConfig("oraproperties.yml")
fmt.Println("Load config complete")
orrrr := sbconfig.DB_Username + "/" + sbconfig.DB_Password + "@" + "//" + sbconfig.DB_Ip + ":" + sbconfig.DB_Port + "/" + sbconfig.DB_Schema
fmt.Println("orrr formed: ", orrrr)
db, err := sql.Open(sbconfig.DbType, orrrr)
if err != nil {
logger.Println("database connection failed...")
logger.Fatal(err)
}
//Use a backoff/retry strategy - we can start this client before
//the database is started, and see it eventually connect and process
//queries
var dbError error
maxAttempts := 20
for attempts := 1; attempts <= maxAttempts; attempts++ {
logger.Println("pinging database...")
dbError = db.Ping()
if dbError == nil {
logger.Println("database ping successfull........")
fmt.Println("database ping successfull........")
break
}
logger.Println("Ping failed: ", dbError, "retry in ", attempts, " seconds.")
time.Sleep(time.Duration(attempts) * time.Second)
}
if dbError != nil {
logger.Fatal(dbError)
}
return db
}
It fails to connect, whereas in java if I specify username, password, port, servicename and tablename in JDBC connection string it connects successfully.
The output is
time="2017-10-10T13:43:02+05:30" level=info msg="Open the database"
time="2017-10-10T13:43:02+05:30" level=info msg="pinging database..."
time="2017-10-10T13:43:24+05:30" level=info msg="Ping failed: ORA-12170: TNS:Connect timeout occurred
retry in 1 seconds."
time="2017-10-10T13:43:25+05:30" level=info msg="pinging database..."
time="2017-10-10T13:43:46+05:30" level=info msg="Ping failed: ORA-12170: TNS:Connect timeout occurred
retry in 2 seconds."