how to use oracle tnsnames.ora?
Answered
Hi, I know that "how-to" is described in documentation. The problem is, that it does not work.
I have tnsnames.ora in my home directory, so I set field TNSADMIN to /home/mmucha, specified TNSNAME, user and pass, but I'm getting
oracle.net.ns.NetException: could not resolve the connect identifier <tnsName>
What is the correct way how to use tnsnames.ora?
Please sign in to leave a comment.
Hello,
please tell us your Oracle server version and JDBC driver version used for data source in IDE.
DB: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
oracle driver: ver. 12.2.0.1 [latest]
and which OS you are running?
Ubuntu 18.04.4 LTS
comment: oracle DB is NOT installed on this system at all. I just have tnsnames.ora here. Hundreds of DBs lives elsewhere, I just need to connect to them reasonably quickly. If it's not possible from this window, but it is somehow possible from shell, this would be even better for me.
Please attach DataGrip log, it can be found under 'Help -> Compress logs and show in..' menu.
It's intellij idea, not datagrip. I'm not sure if I can share logs I'm not sure they not contain something private. So I read them for you, and stuff like usernames etc. ... I had to change them; but I did it using ideas search replace, so it was replaced on all lines equally.
tnsnames.ora contains these lines:
tnsadmin field was set to dir containing tnsnames.ora
tnsname to IHadToChangeThis2
user was set to: IHadToChangeThis
valid password was provided.
in idea.log this can be found:
What is the IDEA version?
IntelliJ IDEA 2019.3.3 (Ultimate Edition)
Build #IU-193.6494.35, built on February 11, 2020
Licensed to Home Credit International a.s.
Runtime version: 11.0.5+10-b520.38 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-76-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 2988M
Cores: 12
Registry: ide.tooltip.initialDelay=905
Non-Bundled Plugins: BashSupport, DeltaTabs, Lombook Plugin, Rearranger, String Manipulation, claims.bold.intellij.avro, com.dmarcotte.handlebars, com.dubreuia, com.khmelyuk.multirun, io.codearte.props2yaml, net.seesharpsoft.intellij.plugins.csv, org.asciidoctor.intellij.asciidoc, org.sonarlint.idea, training
We need a line like:
2020-01-15 08:54:56,103 [ 70631] INFO - ution.rmi.RemoteProcessSupport - "C:\Program Files\JetBrains\DataGrip 2019.2.5\jbr\bin\java" -Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=127.0.0.1 -Duser.timezone=UTC -Dfile.encoding=windows-1252 -classpath "C:\Program Files\JetBrains\DataGrip 2019.2.5\lib\util.jar;C:\Program Files\JetBrains\DataGrip 2019.2.5\lib\trove4j.jar;C:\Program Files\JetBrains\DataGrip 2019.2.5\lib\groovy-all-2.4.17.jar;C:\Program Files\JetBrains\DataGrip 2019.2.5\plugins\DatabaseTools\lib\jdbc-console.jar;C:\Program Files\JetBrains\DataGrip 2019.2.5\plugins\DatabaseTools\lib\dekaf-single-2.0.0.390.jar" com.intellij.database.remote.RemoteJdbcServer oracle.jdbc.OracleDriver
After removing all duplicates, I found 2 different lines you asked for in yesterday log, but maybe it's just different parameter order.
Hm, `-Doracle.net.tns_admin=/home/mmucha` means that we've passed everything to JDBC driver and now it's turn.
Have you been able to use this tnsnames.ora with native oracle tools?
Is tns name camel-cased like in your example? Or does it contain non-alphabetic symbols?
Could you try minimizing your tnsnmaes.ora file to only this entry, try simple alias for it?
If I rewrite manually data from this tnsnames.ora into intellj idea dialog, I can log in.
If I use this file with free sqldeveloper (by putting it into directory sqldeveloper/tns/) I am able to create new connections.
some examplary line looks like this. I cannot grant all entries looks like this(>25K LOC), but most do. I never saw any non-ascii symbol. I never saw lower case letter. Casing kept, letters transformed to A, numbers to 1.
# 18.10.2019 11:17
AAAAAA.AA.AAAAAA=
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=AAAAA1-AA.AAA.AAA)(PORT=1521))(CONNECT_DATA=(UR=A)(SERVICE_NAME=AAAAAA.AAAAA.AA)(SERVER=DEDICATED)))
# 14.06.2018 11:38
AAA1AA.AA.AAAA=
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=AAAAAA1.AA.AAAA)(PORT=1521))(CONNECT_DATA=(UR=A)(SERVICE_NAME=AAAAA1AA.AA.AAA)(SERVER=DEDICATED)))
If it is problem, is it possible to create DS from command line anyhow? If it would be possible to contact idea from shell to create DS it would be the best. Like openning files from shell. If oracle driver does not cooperate, would it be able to just call idea somehow with all information? Definitely easy to do on my side ...
It is said here https://github.com/utPLSQL/utPLSQL-cli/issues/88 that dots in the aliases names do not work in JDBC.
As for command line data source creation - no, that is not possible.
You can paste strings like
in the url
1. how is utPLSQL related?
2. where on that page is stated, that dots in the aliases does not work in jdbc? But OK, I did similar research on "dots in alias" research, and found this, which is more relevant. https://stackoverflow.com/questions/23010218/using-tns-alias-with-ojdbc-12-1
But notice two things:
a) generated exception explicitly says, that there are dots in alias which are not allowed
b) in comment under accepted answer bradley claims, that this bug was fixed by oracle in 12.1.0.2, while I use newer 12.2.0.1.
thus from these two things: I'm using newer driver + I'm not getting exception about dots, but about:
I'd think it's not the case.
3. but OK, let give it a try. I changed alias `some.alias.we.use` to `some_alias_we_use` as both links mentions as a workaround. The result is:
so I don't think this is anyhow related to dots.
and one more testing with aliases:
If I use longer alias corresponding to regex [A-Z_], I got this:
however if I rename that alias to just A, like literally one uppercase char A, I got this:
I even tried copy-pasting strings as you mentioned, so I put connection type "URL only" and place there a string — no, does not work.
BUT if I take that connection string and human parse it, selecting host, service name, port and user into "service name" type of connection dialog — it works immediately.
I don't know, but I think there is something wrong. Well I definitely can write bash script to parse that connection string and use xdotool to type it out for me, but I'm not sure if that's the correct way to use intellij dialogs ;) (but thinking about it, I will do that, that's pretty trivial and fast as well)
Looks like tns name handling a bit broken in thin driver, so we may some day implement alias substitution on our side.
So `_`'s seems to be invalid characters too.
If you are not afraid of using command line tools, you can always generate directly to .idea/dataSources.xml ;)
PS. This page https://geek-tips.github.io/articles/485122/index.html insists that
works. Maybe you've copy-pasted multiline definition in url? I don't know what'll happen with line breaks.
also it is strange, that you have the timeout (in @A attempt)
I will retry that connection string later, maybe it was multiline, cannot grant that.
also `_` removal won't fix that, because I already stated, that even single letter A as alias does not work, and I don't think we can go with char removal any further ...
datasource.xml is watched for changes or do I have to shutdown, modify and start upon every change?
Yes, you need to stop IDE before modifications