sijms / go-ora

Pure go oracle client
MIT License
767 stars 168 forks source link

ORA-12564: TNS connection refused when using BuildJDBC #521

Closed ColinLeeCampbell closed 2 months ago

ColinLeeCampbell commented 4 months ago

I'm currently facing an issue when trying to connect using BuildJDC function with the a orclNetDescString similar to the following: DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=host.com)(PORT=port))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service))(SECURITY=(SSL_SERVER_CERT_DN="CN=cname,O=org,L=location")))

Using the following code

package main

import (
    "database/sql"
    "log"
    "path/filepath"

    _ "github.com/sijms/go-ora/v2"
    go_ora "github.com/sijms/go-ora/v2"
)

func main() {

    desc :=`DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=host.com)(PORT=port))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=service))(SECURITY=(SSL_SERVER_CERT_DN="CN=cname,O=org,L=location")))`

    username := "admin"
    password := "secret"

    walletPath, err := filepath.Abs("wallet")
    if err != nil {
        log.Fatal(err)
    }

    urlOptions := map[string]string{
        "TRACE FILE": "trace.log",
        "AUTH TYPE":  "TCPS",
        "SSL":        "TRUE",
        "SSL VERIFY": "FALSE",
        "WALLET":     walletPath,
    }
    connectString := go_ora.BuildJDBC(username, password, desc, urlOptions)
    db, err := sql.Open("oracle", connectString)
    if err != nil {
        log.Fatal(err)
    }

    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("Connected to Oracle: %s\n\n", connectString)
}

I am getting the ORA-12564: TNS connection refused error.

But when I create a connection string, using the values from the orclNetDescString, I'm able to connect successfully. Here's an example:

package main

import (
    "database/sql"
    "log"
    "path/filepath"

    _ "github.com/sijms/go-ora/v2"
    go_ora "github.com/sijms/go-ora/v2"
)

func main() {
    username := "admin"
    password := "secret"

    walletPath, err := filepath.Abs("wallet")
    if err != nil {
        log.Fatal(err)
    }

    connectString := fmt.Sprintf("oracle://%s:%s@%s:%s/%s?SSL=TRUE&SSL VERIFY=FALSE&AUTH TYPE=TCPS&WALLET=%s", username, password, "host.com", "port", "service", walletPath)
    db, err := sql.Open("oracle", connectString)
    if err != nil {
        log.Fatal(err)
    }

    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("Connected to Oracle: %s\n\n", connectString)
}

Any ideas as to what could be causing the ORA-12564: TNS connection refused error when only using BuildJDBC function?

sijms commented 4 months ago

hi @ColinLeeCampbell remove security section (SECURITY=(SSL_SERVER_CERT_DN="CN=cname,O=org,L=location") and test again

ColinLeeCampbell commented 4 months ago

@sijms - Is there any way we can look into allowing for the security section? It's needed to verify certs.

sijms commented 3 months ago

we will discuss this issue with #517

sijms commented 2 months ago

Custom configuration is supported in v2.8.12