oracle odbc driver configuration - oracle11g

I'm having a problem with configuring oracle odbc
the dialog page is blank
when I enter TNS name as : XE
I get the following error:
unable to connect SQLState=08004
my tnsnames file is:
KPI_SERVER=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =localhost)(PORT =1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)
the connection is successful in SQL developer by the following data:
hostname: localhost
port number: 1521
service: XE
and the trns_admin variable is set to: C:\oracle_odbc\tnsnames
Path is set to: C:\oracle_odbc
what did I do wrong?
thank you for your time

We try to make order: open a command prompt,
launch echo %TNS_ADMIN% the result is C:\oracle_odbc\?
launch dir C:\oracle_odbc\, the result is tnsnames.ora?
launch type C:\oracle_odbc\tnsnames.ora the result is the content of "my tnsnames file is" section of your initial post?
If all the response are yes, can you retry to lauch 'sqlplus.exe dbuser/dbpassword#KPI_SERVER

Related

Airflow - MSSQL connection works on UI but fails in DAG run

On Airflow 2.2.4 (Postgres and Celery).
I have a connection created for Microsoft SQL Server. When I try to test the connection, UI asked me to enter API Auth user/password (Basic Auth) and showed up a green flash "Connection successfully tested"
But,
When I use the same connection ID in an Operator definition to run some SQL queries, I am getting an error as below.
pymssql._mssql.MSSQLDatabaseException: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (<IP>)\nNet-Lib error during Connection timed out (110)\n
DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (<IP>)\n
Net-Lib error during Connection timed out (110)\n')
Here is what my code from my custom operator looks like,
def get_update_num(self):
conn = None
try:
query = f"""
UPDATE SOME_TABLE
SET COL_A = COL_A+1
OUTPUT INSERTED.COL_A
WHERE COL_ID='12345'
self.log.info(f"SQL = {query}")
conn_id = self.conn_id # This is equal to MSSQL_CONNECTION
hook = MsSqlHook(mssql_conn_id=conn_id)
conn = hook.get_conn()
hook.set_autocommit(conn, True)
cursor = conn.cursor()
cursor.execute(query)
row = cursor.fetchone()
self.log.info(f"row = {row}")
return row[0]
except Exception as e:
message = "Error: Could not run SQL"
raise AirflowException(message)
finally:
if not conn:
conn.close()
Any help would be much appreceated.

Unable to connect Corda node to Postgres with SSL

My Postgres DB in GCP (Google Cloud Platform) only accepts connections over SSL.
I tried the below inside my node.conf without any success:
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://db-private-ip:5432/my_node"
dataSource.ssl = true
dataSource.sslMode = verify-ca
dataSource.sslRootCert = "/opt/corda/db-certs/server-ca.pem"
dataSource.sslCert = "/opt/corda/db-certs/client-cert.pem"
dataSource.sslKey = "/opt/corda/db-certs/client-key.pem"
dataSource.user = my_node_db_user
dataSource.password = my_pass
}
I'm sure that the keys (sslMode, sslRootCert, sslCert, and sslKey) are acceptable in node.conf (even though they are not mentioned anywhere in Corda docs), because in the logs I didn't get any errors that those key are not recognized.
I get this error when I try to start the node:
[ERROR] 21:58:48+0000 [main] pool.HikariPool. - HikariPool-1 - Exception during pool initialization. [errorCode=zmhrwq, moreInformationAt=https://errors.corda.net/OS/4.3/zmhrwq]
[ERROR] 21:58:48+0000 [main] internal.NodeStartupLogging. - Could not connect to the database. Please check your JDBC connection URL, or the connectivity to the database.: Could not connect to the database. Please check your JDBC connection URL, or the connectivity to the database. [errorCode=18t70u2, moreInformationAt=https://errors.corda.net/OS/4.3/18t70u2]
I tried adding ?ssl=true to the end of the data source URL as suggested in (Azure Postgres Database requires SSL Connection from Corda) but that didn't fix the problem.
Also for the same values I'm able to use the psql client to connect my VM to the DB:
psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=db-private-ip user=some-user dbname=some-pass"
Turns out the JDBC driver cannot read the key from a PEM file, it has to be converted to a DER file using:
openssl pkcs8 -topk8 -inform PEM -in client-key.pem -outform DER -nocrypt -out client-key.der
chmod 400 client-key.der
chown corda:corda client-key.der
More details here: https://github.com/pgjdbc/pgjdbc/issues/1364
So the correct config should look like this:
dataSourceProperties {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
dataSource.url = "jdbc:postgresql://db-private-ip:5432/db-name"
dataSource.ssl = true
dataSource.sslMode = verify-ca
dataSource.sslRootCert = "/opt/corda/db-certs/server-ca.pem"
dataSource.sslCert = "/opt/corda/db-certs/client-cert.pem"
dataSource.sslKey = "/opt/corda/db-certs/client-key.der"
dataSource.user = db-user-name
dataSource.password = db-user-pass
}

Is it possible to use Oracle Wallet for node connection to its vault?

Is it possible to start an enterprise node, using an Oracle 12c backed up
vault configured via Oracle Wallet (i.e., configure the node.conf using only a
dataSource.url="jdbc:oracle:thin:#host:port:#SOME_ORACLE_WALLET_TNS" without
specifying any dataSource.username or dataSource.password parameters ) ?
In this case, please inform which additional oracle .jar files should be
added to the node drivers dir.
Oracle wallet is supported in Corda Enterprise. Below is a working configuration with Oracle Wallet, and has been tested with Oracle 11g and Oracle 12c.
Prerequisites
Oracle wallet is configured with auto login (-auto_login_local) for the node's database
Assuming that the node's database connection URL is configured in tnsnames.ora, with alias "db11g":
$ echo 'For JDBC URL ==> "jdbc:oracle:thin:#localhost:1521/xe" ==> below is an example of tnsnames.ora'
$ cat ~/oracle_experiment/tnsnames.ora
db11g =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xe)
)
)
Wallet location is configured in sqlnet.ora:
$ cat ~/oracle_experiment/sqlnet.ora
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /Users/corda/oracle_wallet/)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 0
Sqlplus should be able to login without a password challenge:
sqlplus /#db11g
SQL*Plus: Release 12.2.0.1.0 Production on Tue Nov 27 15:17:00 2018
Copyright (c) 1982, 2017, Oracle. All rights reserved.
Last Successful login time: Tue Nov 27 2018 14:46:09 +08:00
Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL>
Necessary steps
Change the database-specific configuration from:
$ cat dbconfig_oracle11g.conf
dataSourceProperties = {
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
dataSource.url = "jdbc:oracle:thin:#localhost:1521/xe"
dataSource.user = corda_es_user
dataSource.password = corda_es_passwd
}
To
$ cat dbconfig_oracle_wallet.conf
dataSourceProperties = {
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
dataSource.url = "jdbc:oracle:thin:/#db11g"
dataSource.user=null
dataSource.password=null // user and password can't be ignored and can't be left blank.
}
Download and copy the following JARs into the node's drivers folder:
]$ ls <corda>/drivers/
ojdbc8.jar
osdt_cert.jar
osdt_core.jar
oraclepki.jar
Start the node with the oracle.net.wallet_location and oracle.net.tns_admin options:
]$ java -Doracle.net.wallet_location=/Users/corda/oracle_wallet/ -Doracle.net.tns_admin=/Users/corda/oracle_experiment/ -jar corda.jar
Refer to the SSL with JDBC blog for more details.

tnsping resolves but not able to connect using script

I am not able to connect to an oracle database from my R/Python scripts. Following is the code. TNSPing utility is able to resolve the database using LDAP. I am pasting TNSPING output as well.
TNSPing output
C:\Windows\System32>tnsping UHK00500_SECCOMPAS_APPL
TNS Ping Utility for 32-bit Windows: Version 11.2.0.2.0 - Production on 12-APR-2
013 10:26:26
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
c:\apps\oracle\network\admin\sqlnet.ora
Used LDAP adapter to resolve the alias
Attempting to contact (DESCRIPTION = (SDU = 8192) (TDU = 8192) (ADDRESS_LIST = (
ADDRESS = (PROTOCOL = TCP)(HOST = PHKLOD2002-SCAN.ap.hedani.net)(PORT = 1522)) (
LOAD_BALANCE = on) (FAILOVER = on ) ) (CONNECT_DATA = (SERVICE_NAME = UHK00500_S
ECCOMPAS_APPL.WORLD) (FAILOVER_MODE = (TYPE = session) (METHOD = basic) (RETRIES
= 20) (DELAY = 5))))
OK (60 msec)
R script output
Oracle 11g driver
chan <- odbcDriverConnect("driver=Oracle in OraHome112_32;DBQ=UHK00500_SECCOMPAS_APPL;UID=toolkit;PWD=**")
Warning messages:
1: In odbcDriverConnect("driver=Oracle in OraHome112_32;DBQ=UHK00500_SECCOMPAS_APPL;UID=toolkit;PWD=**") :
[RODBC] ERROR: state 08004, code 12154, message [Oracle][ODBC][Ora]ORA-12154: TNS:could not resolve the connect identifier specified
2: In odbcDriverConnect("driver=Oracle in OraHome112_32;DBQ=UHK00500_SECCOMPAS_APPL;UID=toolkit;PWD=**") :
ODBC connection failed
ODBC driver output
chan <- odbcDriverConnect("Driver={Microsoft ODBC for Oracle};Server=UHK00500_SECCOMPAS_APPL;Uid=toolkit;Pwd=**")
Warning messages:
1: In odbcDriverConnect("Driver={Microsoft ODBC for Oracle};Server=UHK00500_SECCOMPAS_APPL;Uid=toolkit;Pwd=*") :
[RODBC] ERROR: state 08001, code 12154, message [Microsoft][ODBC driver for Oracle][Oracle]ORA-12154: TNS:could not resolve the connect identifier specified
2: In odbcDriverConnect("Driver={Microsoft ODBC for Oracle};Server=UHK00500_SECCOMPAS_APPL;Uid=toolkit;Pwd=**") :
ODBC connection failed
Can someone please advice what i should check here to correct this issue?
not sure what the issue was, but after restarted my R instance the connection was fine.

How to access the KMDF driver from Client application

I have written a sample KMDF driver. I dont know if I did every thing right but have seen KMDF driver printing Debug message in DebugView utility - when I added this driver as new hardware. It also showed up as "Sample Device" under device manager.
Now I want to write a sample client that could call this Driver - so I can establish a connection between driver and client. I read that we need to use 'CreateFile' and 'DEviceIOControl' etc. But I am not able to get a start on it.
Can you please guide me around creating sample client to access the sample KMDF driver ?
My INF file for the driver looks like this :-
***My INF FILE****
; myshelldriver.INF
; Windows installation file for installing the myshelldriver driver
; Copyright (c) Microsoft Corporation All rights Reserved
;
; Installation Notes:
;
; Using Devcon: Type "devcon install myshelldriver.inf myshelldriver" to install
;
[Version]
Signature="$WINDOWS NT$"
Class=Sample
ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171}
Provider=%MSFT%
DriverVer=09/24/2012,1.0
CatalogFile=myshell.cat
[DestinationDirs]
DefaultDestDir = 12
[ClassInstall32]
Addreg=SampleClassReg
[SampleClassReg]
HKR,,,0,%ClassName%
HKR,,Icon,,-5
[DiskCopyfiles]
wdfmyshelldriver.sys
[SourceDisksNames]
1=%InstDisk%,
[SourceDisksFiles]
Wdfmyshelldriver.sys=1
[Manufacturer]
%MSFT% = DiskDevice,NTAMD64
; For Win2K
[DiskDevice]
%DiskDevDesc% = DiskInstall, wdfmyshelldriver
; For XP and later
[DiskDevice.NTAMD64]
%DiskDevDesc% = DiskInstall, wdfmyshelldriver
[DiskInstall.NT]
CopyFiles = DiskCopyfiles
;;specify that this is the installation
;;for nt based systems.
[DriverInstall.ntx86]
DriverVer=09/24/2012,1.0
CopyFiles=DriverCopyFiles
[DiskInstall.NT.Services]
AddService = wdfmyshelldriver, %SPSVCINST_ASSOCSERVICE%, DiskServiceInst
[DiskServiceInst]
ServiceType = %SERVICE_KERNEL_DRIVER%
StartType = %SERVICE_DEMAND_START%
ErrorControl = %SERVICE_ERROR_NORMAL%
DisplayName = %DiskServiceDesc%
ServiceBinary = %12%\Wdfmyshelldriver.sys
AddReg = DiskAddReg
[DiskAddReg]
HKR, "Parameters", "BreakOnEntry", %REG_DWORD%, 0x00000000
HKR, "Parameters", "DiskSize", %REG_DWORD%, 0x00100000
HKR, "Parameters", "DriveLetter", %REG_SZ%, "R:"
HKR, "Parameters", "RootDirEntries", %REG_DWORD%, 0x00000200
HKR, "Parameters", "SectorsPerCluster", %REG_DWORD%, 0x00000002
[Strings]
MSFT = "Microsoft"
ClassName = "My Shell Device"
DiskDevDesc = "WDF My Shell Driver"
DiskServiceDesc = "myshelldriver Driver"
InstDisk = "myshelldriver Install Disk"
;*******************************************
;Handy macro substitutions (non-localizable)
SPSVCINST_ASSOCSERVICE = 0x00000002
SERVICE_KERNEL_DRIVER = 1
SERVICE_DEMAND_START = 3
SERVICE_ERROR_NORMAL = 1
REG_DWORD = 0x00010001
REG_SZ = 0x00000000
**** END OF INF FILE***
There are many relevant samples in the WDK. For example, take a look at KMDF Echo sample.
First you will need to name your object.
Second you will need to do at least one of the following:
Create a Symbolic link in the \GLOBAL??\
Register a Device Interface.
Option 1 will let you do the simple
CreateFile("\\\\.\\<device_name>, ...);
Option 2 and you will need to use the Setup DI Api routines to find your device to open it.

Resources