Spark Streaming Oracle JDBC sink with wallet - oracle

I am developing a Spark Streaming application which would listen to a folder (partitioned as yyyyMMdd) and aggregate the number of records written per minutes then persist the results to an Oracle table.
I have developed a JDBCSink (ForeachWriter) and in the open method I'm trying to open a connection to Oracle but I am getting "oracle.net.ns.NetException: could not resolve the connect identifier" exception while creating the Oracle connection. I am using Oracle wallet (SSO) and I'm able to connect over sqlplus using this wallet by setting TNS_ADMIN environment variable.
I am pushing the tnsnames.ora, sqlnet.ora, cwallet.sso and ewallet.p12 with the spark-submit --files option, and I have verified the files are pushed to the executors with the SparkFiles.get method in the sink class. I have also added third party Oracle dependencies for Oracle wallet with spark-submit --jars option (namely ojdbc7.jar,oraclepki.jar,osdt_cert.jar,osdt_core.jar)
The code piece for opening the connection is as follows:
Class.forName("oracle.jdbc.driver.OracleDriver")
System.setProperty("oracle.net.tns_admin", new Path(SparkFiles.get("tnsnames.ora")).getParent.getName)
val ds = new OracleDataSource()
val props = new Properties()
props.setProperty(OracleConnection.CONNECTION_PROPERTY_WALLET_LOCATION,
new Path(SparkFiles.get("cwallet.sso")).getParent.getName)
ds.setConnectionProperties(props)
ds.setURL("jdbc:oracle:thin:#xe")
I have tried to isolate the problem
The Oracle version is 12.1.0.2 (I am using a Docker image)
spark-submit2 ^
--master local ^
--files "%CWD%\wlt\tnsnames.ora,%CWD%\wlt\sqlnet.ora,%CWD%\wlt\cwallet.sso,%CWD%\wlt\ewallet.p12" ^
--jars "%CWD%\lib\ojdbc7.jar,%CWD%\lib\oraclepki.jar,%CWD%\lib\osdt_cert.jar,%CWD%\lib\osdt_core.jar" ^
--class OJDBCSinkMain ^
.\target\spark-streaming-ojdbc-sink-1.0-SNAPSHOT-jar-with-dependencies.jar
My sqlnet.ora file is as follows:
NAMES.DIRECTORY_PATH=(TNSNAMES, EZCONNECT)
SQLNET.WALLET_OVERRIDE=TRUE
SSL_CLIENT_AUTHENTICATION=FALSE
SSL_VERSION=0
and my tnsnames.ora file is:
xe =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xe)
)
)
I also verified the credentials for Oracle service xe exists in my wallet:
comment mkstore -wrl . -listCredential
List credential (index: connect_string username)
1: xe system
Do you have any comments? Thanks in advance.

My mistake, I needed a rubber dock to spot!!! SparkFiles.get("tnsnames.ora")).getParent.getName returns relative path, not the absolute. My problem is solved now.

Related

Can't login,ORA-12154: TNS:could not resolve the connect identifier specified

I'm trying to go to PL-SQL Developer, I enter the name of the database, which is on another computer. The result is the following error.
I must say right away that this database is registered in the TNS file, like other databases.
myDB1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ***IP-adress***)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = myDB1)
)
)
What is in the computer's TNS file is also in the client's file. On the host computer, the database works and starts, but not on the client. The database service has started. As I understand it, the client does not need to create a listener, the main thing is that there should be tnsnames.ora. I went through the names and myDBB1, myDBDB, myDataBase and myDB and through dots and spaces its IP address, but the error did not disappear. Other bases on the client computer work without problems.

Oracle Database Connection Error Listener Refused the Connection

I just installed Oracle 11g on my work dev computer which has Windows 7 64-bit and is on a network with a domain set up. When I try to connect to the "XE" database/SID using SQL Developer I get the following errors list below.
Any ideas?
I've researched online and tried a number of the solutions suggested and cannot get it to work. I can confirm the following:
The database is started. I can connect using SQL Plus.
Both the OracleServiceXE and OracleXETNSListener services are started
Internet Information Systems (IIS) is installed and working properly.
In addition to not being able to connect with SQL Developer, when I the the "Get Started" web application, it doesn't work.
When I first tried to connect, the settings in SQL Developer were as follows:
Hostname: localhost
Port: 1521
SID: xe
However, I got the following error:
Status : Failure -Test failed: Listener refused the connection with the following error: ORA-12505
After researching I found that I should look at the listener end points (whatever that means) in the "listner.ora" file and confirm the hostname. That file has the following:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\Oracle\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = extproc)
)
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\Oracle\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = mycomputername.abc.de.mycompany.com.)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
When I saw that the host name was different I first tried changing "HOST" in the listener.ora file from "mycomputername.abc.de.mycompany.com." to "localhost" and then to "127.0.0.1" (note the previous really has an extra period at the end). After doing that, I still got the same error message.
Then, I put everything back the way it was in the "listener.ora" file and instead went to SQL Developer and changed my login information to the following:
Hostname: mycomputername.abc.de.mycompany.com. (again... there really is a period at the end)
Port: 1521
SID: xe
I even tried it with just "mycomputername". Again, I got the error message:
Status : Failure -Test failed: Listener refused the connection with the following error: ORA-12505
I found help from a friend of a friend. Here's what he did.
First, note that he left the settings in the "listener.ora" file alone. Instead he did the following... all from the command prompt.
Step 1: Run SQL Plus directly from the command prompt as the "sysdba" to simulate SQL Plus within the command prompt.
C:\windows\system32>sqlplus / as sysdba
Step 2: Enter the following SQL Plus command to verify the database name (aka global name or SID). The return value was "XE".
SQL> select * from global_name;
Step 3: Enter the following SQL Plus command to set the listner to use the 'localhost' as the "HOST". Apparently, the listener this will override the settings in the "listner.ora" file. I think he said this is saved in the database somewhere and is not saved in a file.
SQL> alter system set LOCAL_LISTENER='(DESCRIPTION_LIST = (DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)
(HOST = localhost)(PORT = 1521))))';
Step 4: Enter the following SQL Plus command to register what you set in step 3 above.
SQL> alter system register;
Step 5: Exit the SQL plus simulation in the command prompt.
SQL> exit

Can't connect to Oracle database with SQL Developer (Ora00604 error occurred at recursive level 1 ORA - 12705)

I have installed Oracle 11g Express Edition from http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index-083047.html and also installed SQL Developer, but when I try connect to Oracle Database from Developer (I try create new connection) next error appears:
Ora00604 error occurred at recursive level 1 ORA - 12705.
What should I enter at: Hostname, port and SID
TNSNAMES provided below:
XE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = DYedilkhan-ПК)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
Add this rows into ..\sqldeveloper\ide\bin\ide.conf file
AddVMOption -Duser.language=en
AddVMOption -Duser.region=us
It's working for me.
if you don't know what language and region to use, you can add
AddVMOption -Duser.region=
(nothing after =)
It worked in my case as macloving solution did too
Solved by changing system language. In my case the problem occurred because Windows decided to change my "display language" to English(Kenyan), and unsurprisingly it wasn't supported by the Database.

How to query an external MS Access DB from an Oracle DB?

How to configure Oracle to be able to query a MS Access database (.accdb) that is lcoated in the same server (localhost)?
Which steps to follow?
Version of Oracle: 11g -> 11.2.0.1.0
Version of Windows: Windows Server 2008
Steps to complete:
Create System DSN with Microsoft Access Driver
Modify listener.ora file
Create the file initaccess.ora
Modify tnsnames.ora file
Restart listener
Check connection with access database
Create the DB Link in Oracle
STEP 1: Create system DSN
First go to ODBC Data Source Administrator click on System DSN tab. The create a DSN with the following parameter (you can choose the name link that you prefer but then you need to keep the same name all over the process).
In our case:
Driver: Microsoft Access Driver (*.mdb,*.accdb)
Name: access
Description: (doesn't matter)
Database -> Select -> (Select the .accdb or .mdb database)
Save the configuration
Make sure you see this listed once you save it:
Name - Driver
access - Microsoft Access Driver (*.mdb,*.accdb)
STEP 2: Modify listener.ora file
Let's locate the file. In our case:
E:\app\Administrador\product\11.2.0\dbhome_1\NETWORK\ADMIN
We need to add the following text at the end. By the way, look at I posted as 'oracle_home' the directory in C: drive. That's because I had more than one directory related to Oracle, and I still don't understand it but worked in my case. Maybe in yours there's only one.
Parameters you need to modify:
In first block:
SID_NAME: name chosen in the step above. The name of the dsn created ('access' in our case)
ORACLE_HOME: Home directory of Oracle
PROGRAM = dg4odbc (I think that from Oracle 11g and beyond, 'dg4odbc' is mandatory.
In second block:
HOST: The name of the hostname (not sure if localhost' or an IP address are supported, but I guess they are)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC=
(SID_NAME = access)
(ORACLE_HOME = C:\app\Administrador\product\11.2.0\dbhome_1)
(PROGRAM = dg4odbc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = host_name)(PORT = 1521))
)
)
Make sure there is no space before 'SID_LIST_LISTENER' or 'LISTENER' in the file you modify:
STEP 3: Create the initaccess.ora file
Go to:
E:\app\Administrador\product\11.2.0\dbhome_1\hs\admin
There, make a copy of 'initdg4odbc.ora' file (I deleted it after I made a copy). Add the following text to the file:
HS_FDS_CONNECT_INFO = access
HS_FDS_TRACE_LEVEL = 0
HS_FDS_CONNECT_INFO: Here we write the name of the link created in the ODBC source tool in the first step, so it's 'access'
HS_FDS_TRACE_LEVEL: Leave it with a 0
STEP 4: Modify tnsnames.ora file:
Let's locate the file. In our case:
E:\app\Administrador\product\11.2.0\dbhome_1\NETWORK\ADMIN
Parameters to modify:
HOST: hostname of the server
SID: this is the name of the 'initaccess.ora' file BUT taking away the 'init' part and '.ora' file extension: then 'access'.
(HS=OK) = don't forget this.
access =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = host_name) (PORT = 1521))
(CONNECT_DATA =
(SID = access)
)
(HS=OK)
)
Be sure that you don't leave spaces before the 'access =' parameter.
STEP 5: Restart the listener
Open a command line terminal
Go to: C:\app\Administrador\product\11.2.0\dbhome_1\BIN
Stop the listener
C:\app\Administrador\product\11.2.0\dbhome_1\BIN>LSNRCTL.EXE stop
You should see a message saying it was successfull
Restart the listener
C:\app\Administrador\product\11.2.0\dbhome_1\BIN>LSNRCTL.EXE start
You should see a message saying it was successfull
You should also see, (in the output, when restarting the server) a message talking about the 'access' service we just added
El servicio "access" tiene 1 instancia(s).
La instancia "access", con estado UNKNOWN, tiene 1 manejador(es) para este ser
vicio...
El comando ha terminado correctamente
STEP 6: Test connection with the access database
Open a command line terminal
Go to: C:\app\Administrador\product\11.2.0\dbhome_1\BIN
Run tnsping.exe (as argument, pass the name of the link: 'access'):
C:\app\Administrador\product\11.2.0\dbhome_1\BIN>tnsping.exe access
You should see a message saying it was correctly run and displaying the delay in msecs
TNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 06-JUN-2
014 11:04:35
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Archivos de parßmetros utilizados:
E:\app\Administrador\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
Adaptador TNSNAMES utilizado para resolver el alias
Intentando contactar con (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = CUPCA
KE) (PORT = 1521)) (CONNECT_DATA = (SID = access)) (HS=OK))
Realizado correctamente (20 mseg)
STEP 7: Create the DB Link in Oracle and query the Ms Access database:
Create the DB Link (always as **sys):**
CREATE public DATABASE LINK accessdblink USING 'access';
* 'access': Same name as in tnsnames.ora -> 'access = '
Query the database:
SELECT * FROM table_name#accessdblink;

Create a Oracle ODBC DSN with Widows. Entering the port number

I have the following entry in my c:\Oracle\product\11.1.0\network\ADMIN\TNSNAMES.ORA file.
enter code herepvtest.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxxx.xxx.xxx)(PORT = 1521))
)
(CONNECT_DATA =
(SID = pvtest)
(SERVER = DEDICATED)
)
)
I could connect successfully using TOAD. Now when I try creating a new ODBC DSN it doesn't allow me to do so. How do I specify the port number in TNS Service Name?
enter code hereGet the following error : ---------------------------
Testing Connection
Unable to connect
SQLState=S1000
[Oracle][ODBC][Ora]ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
OK
When you say you could connect with TOAD, can you do so now that the ODBC connection fails? if you can connect with any tool on your client PC than obviously the listener at the other end knows of the service so you have to suspect your end. Probably one client tool is trying to reach PVTEST at a diffrerent location than the other.
If one client tool can connect and the other cannot, first of I would confirm that both clients are using the same tnsnames.ora file. Search your client and see if there are other tnsnames.ora files which would imply other ORACLE_HOMES (Google that if you don't know what it is).
From a command line do a TNSPING and see if it reaches the host. It will also tell about the connection details.
In TOAD check the connection details and ensure it is using a tnsnames connection and if so which tnsnames.
Check if your client has the environment variable TNS_ADMIN set.
I have this kind of block with Oracle XE:
XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = test.acme.org)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
If you compare that with yours definition, not that there is "SERVICE_NAME" parameter.

Resources