Adding a `defaultPort` to conn.URL leads to invalid Connection String with Oracle TNS and TCPS
Closed this issue · 1 comments
Hi @flarco,
I opened an issue with an Oracle TCPS connection over at Sling-CLI a while ago: slingdata-io/sling-cli#80.
I did not follow up with the issue but took some time to analyse what's happening this week. I set up a simple go program using godror and used an Oracle TNS Connection String as I want to connect using a secure connection via TCPS, ie
db, err := sql.Open(
"godror",
fmt.Sprintf(`user="%s" password="%s" connectString="%s"`, os.Getenv("USER"), os.Getenv("PASSWORD"), os.Getenv("TNS")),
)
where $TNS
is similar to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=my-oracle-database.provider.com)(PORT=7777))(CONNECT_DATA=(SID=my_service)))
This works as expected. When I use the same credentials to connect using Sling-CLI, I get an error
ORA-12154: TNS:could not resolve the connect identifier specified
and Sling-CLI logs
params=user=XXXX password="SECRET-an7cEDDPOBI=" connectString="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=my-oracle-database.provider.com)(PORT=7777))(CONNECT_DATA=(SID=my_service))):1521"
. Sling-CLI seems to add the default port to the TNS which results in an invalid TNS.
I suppose the issue is dbio/database/database.go: https://github.com/flarco/dbio/blob/main/database/database.go#L393-L406, where you add the default Oracle Port to the Connection String. The defaultPort
is set in https://github.com/flarco/dbio/blob/main/database/database_oracle.go#L29-L48.
Is there a way to set the defaultPort
to 0 to prevent dbio
from adding the defaultPort to my TNS?
Hey @temminks, figured to allow a connection string override would be the best path forward.
So, in next release of sling (slingdata-io/sling-cli#129), you'll be able to provide the conn_str
property to override the built-in generated conn string. See 1cc2183.