jdbc using sqlnet.ora - oracle

I have a program that wants to make a connection to an oracle database on our network. This program is written in java and has to use jdbc. Our PC's are setup to use sqlnet.ora files to determine the order of how to resolve. All our PC's first check ldap (which the ldap file is on all these PC's pointing to the ldap server) and then secondly to use tnsnames.ora file, but this file is empty now so basically I want to use ldap, but do it via sqlnet.ora. Any ideas what the connection would look like for the url parameter?

From the JDBC Developer's Guide
The oracle.net.tns_admin system property must be set to the location of the tnsnames.ora file so that the JDBC Thin driver can locate the tnsnames.ora file. For example:
System.setProperty("oracle.net.tns_admin", "c:\\Temp");
String url = "jdbc:oracle:thin:#tns_entry";
DriverManager.getConnection(url, ...);
Because of the system property, the thin driver is able to locate the tnsnames.ora file and thus can resolve the TNS name specified in the URL. Because the thin driver is usually intended to work without an Oracle client installation, this is not enabled by default.
As far as I remember, you only need tnsnames.ora, you don't need an Oracle client when using the thin driver even when specifying a TNS name.
If your program does not allow setting system properties you have two options:
Specify it when starting your program java -Doracle.net.tns_admin=c:/foobar ...
Set an environment variable JAVA_TOOLS_OPTIONS that contains -Doracle.net.tns_admin=c:/foobar. That will then be picked up by any Java program automtically

From the Oracle JDBC FAQ
jdbc:oracle:oci:#<<TNS alias>>
where <<TNS alias>> is the LDAP entry that you would use if you were connecting via, say, SQL*Plus

Related

Need to Connect by Proxy with ODP.NET Using My Certificate

I'm having an issue making a proxy database connection to an ORACLE database using ODP.net. I need my program to attempt the proxy connection but then prompt me for my certificate and authenticate me with that.
I have a Perl script that does this and it only requires me to specify the name of the TNS entry and the user I want proxying in for me.
I also have my SQL Developer doing the same thing, pointing to the same TNS entry.
But when I try to attempt the same approach with ODP.NET it just gives me the ORA-12154 error, "TNS: Could not resolve the connect identifier specified."
From my limited knowledge of Oracle I ASSUME that the error means that it couldn't find that TNS entry. And I've verified that the entry DOES exist in my tnsnames.ora file and proved I could proxy to it via my Perl script and SQL Developer. Even put a breakpoint in my VB code to ensure I was specify the correct TNS Entry.
I've even stripped down the connection string to JUST the datasource to see what error I get. So I'm not sure if I have the connection string wrong or if it needs to be in a different format. But I DO know that the solution HAS to allow me to specify the TNS alias and the connection HAS to prompt me for my certificate. No password.
So I guess I'm trying to find out what the appropriate connection string would look like to do this and why .NET can't seem to figure out what this TNS alias is.
I've tried setting the USER ID attribute to the account I want proxying for me, set the PROXY USER ID attribute the same way as well as also tried "/", set the DATA SOURCE attribute to the TNS alias.
This program will be deployed to four different environments that have the same TNS alias in them but point to different servers. So I really need to be able to specify the TNS alias.

ORA-12154 error TNS could not resolve the connect identified specified

while running a java application,I am getting ORA- 12154 error.
In the java application we have to Login using our Database credentials. For some user credentials the application is running successfuly but for others it's throwing error ORA-12154:TNS:could not resolve the connect identifer specified.
Can someone please help me with the issue.
The most usual cause for that is that database alias (you're connecting to) isn't included into the TNSNAMES.ORA file.
If you have several Oracle software products, there's a good chance that each of them has its own TNSNAMES.ORA file (usually located in its \network\admin directory). The way of it is to simultaneously edit all those files (which is stupid), or create a TNS_ADMIN environment variable which will point to a directory that contains your "master" TNSNAMES.ORA file, such as I have:
M:\>set tns_admin
TNS_ADMIN=C:\0_Oracle_library
Therefore, every time I have to add a new database, I edit that TNSNAMES.ORA file and all my Oracle programs (Forms, Reports, SQL Developer, TOAD, SQL*Plus, ...) access it and use it.
The Oracle error code documentation has some helpful troubleshooting tips (the following is from 12.1):
ORA-12154: TNS:could not resolve the connect identifier specified
Cause: A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.
Action:
If you are using local naming (TNSNAMES.ORA file):
- Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA)
- Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.
- Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.
- Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable.
If you are using directory naming:
- Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).
- Verify that the LDAP directory server is up and that it is accessible.
- Verify that the net service name or database name used as the connect identifier is configured in the directory.
- Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier.
If you are using easy connect naming:
- Verify that "EZCONNECT" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).
- Make sure the host, port and service name specified are correct.
- Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.
Start by checking whether you can tnsping the specified service (tnsping is a utility included in the Oracle Client). For example, if connecting as x/y#zzz fails with ORA-12154, then
tnsping zzz
This will probably give
TNS-03505: Failed to resolve name
but it will also display the path of the local sqlnet.ora parameter file mentioned above. Depending on your setup there should be other .ora files in the same location.
There are a number of ways this can be configured depending on your OS, Oracle client and name resolution setup. (Note that a tnsnames.ora file is not the only naming method.) If you share some more details it should be straightforward to resolve the issue.

Oracle JDBC driver: How to use /etc/ldap.ora and only specifying SID?

I have an Oracle connection using com.oracle:ojdbc14:10.2.0.2.0 and the URL jdbc:oracle:thin:#fooe2.company.intern:1529:odse but would like to leave away the hostname and port as it may change over time. Using sqlplus I can just say "odse" and it will look the name up via /etc/ldap.ora. I know that there is a syntax where I can specify the ldap server names in the JDBC URL but I don't want that either as it may change as well.
Is it possible to have JDBC make use of the existing /etc/ldap.ora configuration and just specify the SID?

How do you connect to an LDAP server using node-oracledb?

I have a database that I can connect to using jdbc using the string "jdbc:oracle:thin#ldap://SERVER_NAME:1234/SERVICE,cn=OracleContext,dc-world".
However, when I use node-oracledb, this connection string does not work, presumably because Node doesn't use jdbc. What connection string could I use to connect to the database?
There is no "Easy Connect" syntax available for LDAP so you will need
to configure ldap.ora and sqlnet.ora files and use a non-Easy Connect
string alias in node-oracledb (or in other tools like SQL*Plus, PHP OCI8, Python cx_Oracle, Golang godror etc).
I'm told (!) the steps are:
Invoke netca -> Directory Usage
Configure naming to use LDAP by netca->Naming Methods Configuration. This sets up sqlnet.ora for name lookup.
run netmgr to setup the entry in ldap or Enterprise Manager to setup ldap.
Copy those files to a subdirectory on the machine where you run Node.js, and set TNS_ADMIN to the directory containing the files. With Instant Client you can put it in the network\admin subdirectory under the Instant Client libraries. See the manaul entry Optional Oracle Net Configuration
Set node-oracledb's connectString to the connect alias configured in 3, e.g. "orcl"
In order to get an ldap connection to work, I had to do the following:
In the network/admin folder of the oracle client add (These were provided by my db admin, but there are examples here:):
LDAP.ORA
sqlnet.ora
And then the connectString is just the service name and nothing else. So, using the original example jdbc:oracle:thin#ldap://SERVER_NAME:1234/SERVICE,cn=OracleContext,dc-world the connectString would just be SERVICE

Specify a default driver for ODBC

I have a legacy VB6 app which builds a DSN based on a parameter in a config file. The parameter is an ODBC connection, and the connection has a name (DSN-NAME) which maps a server (DBSERVER) to a driver ("SQL Server Native Client").
Generally, it builds a DSN like this:
DSN=DSN-NAME;User=foo;Password=bar
If I specify a hostname in the file, it builds a connection string which says
DSN=DBSERVER;User=foo;Password=bar
The error message reported is:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
This suggests to me that there is perhaps a way of specifying a default driver, which may mean I can specify just the server name in the config file, and not need to create the ODBC connection.
(I am aware these can be created automatically; this is just to simply installation, and to satisfy my curiosity).
How do you specify a default driver? If I can set the default driver to SQL Server Native Client, can I then say DSN=DBSERVER and connect?
Edit: the point was to try and do this without changing the connection string. All the research suggested this isn't actually possible, but he wording of the dialog suggested it might be.
I had the same problem and fixed it by using the 32-bit ODBC admin to create a 32-bit DSN rather than the 64-bit admin in Administrative Tools which only creates 64-bit DSN which don't work.
The 32-bit ODBC Manager is located at C:\Windows\SysWOW64\odbcad32.exe
See this article "Data source name not found and no default driver specified" on Corey Gilmore's blog.
To specify a default driver, use DRIVER= in the connection string:
DRIVER=driver name here;DATABASE=mydb;USER=foo;PASSWORD=bar
The driver name is the name that appears in the Control Panel ODBC config tool for each driver. Note you will need to supply the info which would normally come from the DSN, in this case the database name.
You can achieve what you want by appending ";SERVER=dbserver" to your connection string.
There is already a server specified in your DSN, but the SERVER keyword in your connectionstring will override that.
http://msdn.microsoft.com/en-us/library/ms715433(VS.85).aspx
Use a DSN-less connection string...it can be created 'on the fly' to exactly suite your purposes....no piddling with odbcad32.cpl or reg/ini files to control/configure a dsn required.
see http://support.microsoft.com/kb/147875
for details

Resources