I need help on connecting Oracle Autonomous Database to my .net core mvc app,
has any one tried it or aware about it.
Thanks in Advance
Thank You
Shubham Pratap
Too long for comments.
Download and extract Oracle cloud wallet.Make a backup copy of tnsnames.ora file.Shorten the names of your autonomous database entry(this step is optional.
Add the path of cloud wallet directory in sqlnet.ora
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
SSL_SERVER_DN_MATCH = yes
WALLET_LOCATION =
(SOURCE =
(METHOD = file)
(METHOD_DATA =
(DIRECTORY = "c:\OracleCloudWallet")
)
)
2) Shorten name of autonomous database entry of your choice in tnanames.ora (this step is optional just for convenience sake)
tnsnames.ora file (actual instance name is lengthy over 50 characters)
adw_high = (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=xxx))(connect_data=(service_name=xx))(security=(ssl_server_cert_dn="CN=xxx,......")))
adw_low = (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=xxx))(connect_data=(service_name=xxx))(security=(ssl_server_cert_dn="CN=xxx,......")))
adw_medium = (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=xxx))(connect_data=(service_name=xxx))(security=(ssl_server_cert_dn="CN=xxx,............")))
3)Create system variable for TNS_ADMIN and directory path to cloud wallet directroy
If you set up tns_admin variable properly
from command prompt C:\echo %TNS_ADMIN% should print correct path
4)If all above steps setup properly then you should be able tnsping each entry in tnsnames.ora
Connection string in your code shoulld be like this
// Configure ODP.NET connection string
//Data Source is nothing but adb entry in tnsnames.ora i,e adw_high
optionsBuilder.UseOracle(#"User Id=xxx;Password=xxxxxx;Data Source=adw_high");
// Set TnsAdmin value to directory location of tnsnames.ora and sqlnet.ora files
OracleConfiguration.TnsAdmin = #"c:\OracleCloudWallet";
// Set WalletLocation value to directory location of the ADB wallet (i.e. cwallet.sso)
OracleConfiguration.WalletLocation = #"c:\OracleCloudWallet";
Edit:-
Today Fired up ADW instance and connected without any problem.I have Oracle 19c local instance.
ASP.NET Core Web Application relevant code
OracleConfiguration.TnsAdmin = #"C:\app\oracle\product\19.3.0\db_1\network\admin";
OracleConfiguration.WalletLocation = #"C:\app\oracle\product\19.3.0\db_1\network\admin";
string conString = "User Id=scott;Password=xxxx;Data Source=adw_low";
Related
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.
I have Windows Server 2008 r2 with myora.local domain and AD. There is server Oracle. And I have client on Win7.
On server:
-C:\krb\krb.conf
MYORA.LOCAL
MYORA.LOCAL myora.local admin server
-C:\krb\krb5.realms
[libdefaults]
default_realm=MYORA.LOCAL
[realms]
MYORA.LOCAL= {
kdc=DomainController.myora.local:88
}
[domain_realm]
.local.myora=MYORA.LOCAL
-sqlnet.ora
SQLNET.KERBEROS5_CONF= c:\krb\krb.conf
SQLNET.KERBEROS5_REALMS = c:\krb\krb5.realms
SQLNET.KERBEROS5_CC_NAME = C:\krb\v5srvtab
SQLNET.AUTHENTICATION_SERVICES= (BEQ, TCPS, NTS, KERBEROS5)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
SQLNET.KERBEROS5_CONF_MIT = TRUE
SQLNET.AUTHENTICATION_KERBEROS5_SERVICE = krbtgt
okinit work for Kefir#MYORA.LOCAL (user name on computer-server)
I do all the same steps on client (except sqlnet.ora), but okinit trows error:
From local name user1 it can't find, from computer name It has credential problems.
What should I change or add?
The error may be telling you that for your database service principle (the account you issued the keytab from ) you haven't selected "pre-authentication not required" in account properties.
For your client you should remove beq from the list of authentication services in sqlnet.ora. If you aren't using them also remove NTS (windows native) and TCPS (certificate).
In your krb5.conf file add upper-case to your domain realm, as well as an alias not prefixed by a period - like this:
[domain_realm]
.local.myora=MYORA.LOCAL
local.myora=MYORA.LOCAL
.MYORA.LOCAL=MYORA.LOCAL
MYORA.LOCAL=MYORA.LOCAL
You might want to take a look at this video - there's a chance it will answer other questions you are likely to run into
https://www.youtube.com/watch?v=d_d0j9ssQys&ab_channel=OracleDevelopers
I want to connect my Oracle database (11.2) with a BigQuery table with the Database Gateway for ODBC. The ODBC driver (Test after the configuration is successful) is configured as in the tutorial:
initdg4odbc.ora:
HS_FDS_CONNECT_INFO = "Google BigQuery"
HS_FDS_TRACE_LEVEL = 4
Following entry was added to the listener.ora:
(SID_DESC=
(SID_NAME=DG4ODBC)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
(PROGRAM=dg4odbc)
And to the tnsnames.ora:
BIGQUERY =
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=tcp)
(HOST=localhost)
(PORT=1521))
(CONNECT_DATA=
(SID=DG4ODBC))
(HS=OK)
)
So far it looks good and I can do successful tnsping:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS= (PROTOCOL=tcp) (HOST=localhost) (PORT=1521)) (CONNECT_DATA= (SID=DG4ODBC)) (HS=OK))
OK (10 msec)
Afterwards I have created a database link on the Oracle DB:
CREATE DATABASE LINK google USING 'BIGQUERY';
But once I query the table (the query in Bigquery works find and name is in upper case) via sqlPlus I get the following error message:
SQL> select * from TABLE#bigquery;
select * from TABLE#bigquery
ERROR at line 1:
ORA-28511: lost RPC connection to heterogeneous remote agent using
SID=ORA-28511: lost RPC connection to heterogeneous remote agent using
SID=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DAT
A=(SID=DG4ODBC)))
ORA-02063: preceding line from BIGQUERY
Process ID: 16180
Session ID: 49 Serial number: 51
Any ideas why the error occurs or where I can find more details for it?
Your tutorial is inconsistent. At one point he has you create a DSN named "BigQuery", but then has you set credentials for a DSN named "Google BigQuery". Pick a DSN and stick with it. And this carries back HS_FDS_CONNECT_INFO in your init. ora file.
Also, I'd not name the gateway SID as 'DG4ODBC'. It will work, but is a very mis-leading name. What will you name the next one you have to create? I'd name the SID the same as the target database - BigQuery in this case.
You might find this link to be more helpful .. https://edstevensdba.wordpress.com/2018/09/19/the-oracle-transparent-gateway/
I am trying to make a connection to Oracle DB from VBScript. I've added all the environment variables and the code can locate the file of TNSNAMES.ora but cannot resolve the connection.
When I test the connectivity from the ODBC Data Source Administrator, I get a 'Success' result, but I still cannot access this from the code.
con.ConnectionString = "DSN=DATA;Uid=wh;Pwd=pwd;"
con.Open 'This is where it fails
I have tried many connection strings but all fail
OracleConnString = "Driver={Oracle in instantclient_18_3};server=server;database=db;trusted_connection=Yes;"
DB_CONN_STRING = "Driver={Oracle in instantclient_18_3}; " & _
"(DESCRIPTION=" & _
"(ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = port)" & _
"(CONNECT_DATA=(SERVICE_NAME=srv_name)))"
CONN_STRING = "CONNECT wh/pwd#//host/db"
How can I connect to the database from the script?
You mix several topics.
You hide the DSN name and the "Data Source Name", this makes it impossible for use to provide you the correct connection string.
If you like to use the ODBC DSN then the connection string must be
DSN=▇▇▇▇DATA;Uid=myUsername;Pwd=myPassword
However, you must create a System DSN, not a User DSN (see ODBC DSN). However, typically you don't use the ODBC DSN because you have to create the DSN on the target machine which is additional configuration work.
Connection string without DSN would be
Driver={Oracle in instantclient_18_3};Dbq=?????;Uid=myUsername;Pwd=myPassword;
or
Driver={Oracle in instantclient_18_3};Server=?????;Uid=myUsername;Pwd=myPassword;
see https://www.connectionstrings.com/oracle-in-oraclient11g_home1/
If you use full DB name like (DESCRIPTION=... then you don't need any tnsnames.ora file. The purpose of this file is to resolve an alias to this full DB name.
Ensure that the ODBC driver is the same architecture, i.e. 32-bit or 64-bit as your VBS environment.
Either use %windir%\system32\odbcad32.exe + %windir%\system32\cscript.exe
or %windir%\SysWOW64\odbcad32.exe + %windir%\SysWOW64\cscript.exe
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;