ODBC Data Source Connection Successful but TNS Unresolved in VBScript - oracle

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

Related

What are the best practices for troubleshooting Heterogeneous ODBC connections?

I am trying to establish a heterogeneous ODBC connection from an Oracle 21c XE database to a Progress OpenEdge 11.7 database. I have installed a 32 bit ODBC driver on the Windows 2019 server where the 21c XE DB resides. I have set up an ODBC System DSN, tested it and it works.
I created a initTIMEDATA.ora file in the C:\app\Administrator\product\21c\homes\OraDB21Home1\hs\admin folder.
It contains;
HS_FDS_CONNECT_INFO = TimeData
HS_FDS_TRACE_LEVEL = 4
HS_FDS_TRACE_FILE_NAME = TimeData.trc
Where TimeData matches the ODBC System DSN name.
I modified the listener.ora adding;
(SID_DESC=
(SID_NAME=TimeData)
(ORACLE_HOME=C:\app\Administrator\product\21c\dbhomeXE)
(PROGRAM=C:\app\Administrator\product\21c\dbhomeXE\bin\dg4odbc)
(ENVS = LD_LIBRARY_PATH=C:\Progressx86\OpenEdge\lib:C:\app\Administrator\product\21c\dbhomeXE\bin)
)
I modified my tnsnames.ora file adding;
TIMEDATA=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=10.254.10.41)
(PORT=4621)
)
(CONNECT_DATA=
(SID=TimeData))
(HS=OK))
I created a DBLink like;
CREATE PUBLIC DATABASE LINK time_data_link CONNECT TO "sqluser" IDENTIFIED BY "myPassword" USING 'TIMEDATA';
After restarting everything (DB, Listener...) the listener shows;
Service "TimeData" has 1 instance(s).
Instance "TimeData", status UNKNOWN, has 1 handler(s) for this service...
When I try to run a query;
SELECT * FROM employee_view#time_data_link;
I get;
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from TIME_DATA_LINK
28545. 0000 - "error diagnosed by Net8 when connecting to an agent"
*Cause: An attempt to call an external procedure or to issue SQL
to a non-Oracle system on a Heterogeneous Services database link
failed at connection initialization. The error diagnosed
by Net8 NCR software is reported separately.
*Action: Refer to the Net8 NCRO error message. If this isn't clear,
check connection administrative setup in tnsnames.ora
and listener.ora for the service associated with the
Heterogeneous Services database link being used, or with
'extproc_connection_data' for an external procedure call.
Error at Line: 1 Column: 29
I see no errors in the listener.log, I cannot find TimeData.trc. In poking around the DB trace files I found a trace file related with multiple copies of;
HS connect: nscall returned status ffffffff (-1)
ns main err code: 12569
ns (2) err code: 0
nt main err code: 0
nt (2) err code: 0
nt OS err code: 0
*** 2022-04-03T17:01:07.758909-04:00 (XEPDB1(3))
HS: Unable to establish RPC connection to HS Agent...
HS: ... Agent SID = (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.254.10.41)(PORT=4621))(CONNECT_DATA=(SID=TimeData))), NCR error = 65535 Unable to retrieve text of NETWORK/NCR message 65535
I have reached the end of my troubleshooting skills and hope someone else may be able to point me in the right direction.
I had two problems.
The TNSNAMES.ORA file needed to point to the Oracle DB server, running on localhost in my case. Once I changed this, the error changed to
Error;
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application {IM014}
New TNSNAMES.ORA;
TIMEDATA=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=localhost)
(PORT=1521)
)
(CONNECT_DATA=
(SID=TimeData))
(HS=OK))
Once I saw this error it became apparent I needed the 64 bit version of the ODBC driver which I acquired.
After making these changes everything seems to work.

Connecting Oracle Autonomous Database to .net entity framework

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";

cx_Oracle connection by python3.5

I've tried several attempt to connect Oracle DB but still unable to connect. Following is my code to connect. However, I could connect Oracle DB through the terminal like this:
$ sqlplus64 uid/passwd#192.168.0.5:1521/WSVC
My evironment: Ubuntu 16.04 / 64bit / Python3.5
I wish your knowledge and experience associated with this issue to be shared. Thank you.
import os
os.chdir("/usr/lib/oracle/12.2/client64/lib")
import cx_Oracle
# 1st attempt
ip = '192.168.0.5'
port = 1521
SID = 'WSVC'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
# dsn_tns = cx_Oracle.makedsn(ip, port, service_name=SID)
db = cx_Oracle.connect('uid', 'passwd', dsn_tns)
cursor = db.cursor()
-------------------------------------------------
# 2nd attempt
conn = "uid/passwd#(DESCRIPTION=(SOURCE_ROUTE=OFF)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.5)(PORT=1521)))(CONNECT_DATA=(SID=WSVC)(SRVR=DEDICATED)))"
db = cx_Oracle.connect(conn)
cursor = db.cursor()
------------------------------------------------------
# ERROR Description
cx_Oracle.InterfaceError: Unable to acquire Oracle environment handle
The error "unable to acquire Oracle environment handle" is due to your Oracle configuration being incorrect. A few things that should help you uncover the source of the problem:
when using Instant Client, do NOT set the environment variable ORACLE_HOME; that should only be set when using a full Oracle Client or Oracle Database installation
the value of LD_LIBRARY_PATH should contain the path which contains libclntsh.so; the value you selected looks like it is incorrect and should be /usr/lib/oracle/12.2/client64/lib instead
you can verify which Oracle Client libraries are being loaded by using the ldd command as in ldd cx_Oracle.cpython-35m-x86_64-linux-gnu.so

PDO cannot find ODBC driver

Trying to migrate to PDO for an ODBC connection to a remote database.
My system is Windows 7 Pro, with a FortiClient VPN connection to the remote domain, and Tunnel Mode connected. (Added in edit: Running PHP 5.4, so PDO should be installed by default.)
The data source configuration in the Windows 7 ODBC Data Source Administrator is as follows (some names changed for security):
Under System DSN:
System Data Source Name = 'TheBigDB'
Driver = 'Oracle in instantclient_11_2' (64-bit)
TNS Service Name = '10.10.1.20:1521/BIGDB'
UserID = 'BigDBUser'
All other settings are defaults for installation of driver
The following piece of PHP non-PDO code is able to create a connection usable for queries:
if (!($myConn = odbc_connect('TheBigDB','BigDBUser','myPwd'))) {
echo "No ODBC connection<br />";
}
So I can connect to the database. The problem is doing it in PDO. The following PHP...
try {
$odbcConn = new PDO('odbc:Driver={Oracle in instantclient_11_2};Server=10.10.1.20:1521;Database=BIGDB;Uid=BigDBUser;Pwd=myPwd');
} catch (PDOException $e) {
echo 'PDO connection failed: ' . $e->getMessage();
}
... results in a PDO connection failed: could not find driver message. My first try relied more heavily on the Data Sources Administrator; that looked like this:
try {
$odbcConn = new PDO('MyBigDB','BigDBUser','myPwd');
} catch (PDOException $e) {
echo 'PDO connection failed: ' . $e->getMessage();
}
Same thing -- could not find driver.
So here's my question: Given a Windows 7 system with ODBC through a VPN connection to an Oracle database that all seems to work without PDO, how do I migrate the connection parameters to create a PDO connection? Maybe a better question is why mess with PDO for the connection, but I keep reading that PDO is more secure, so I'm trying to use it.
More digging got me an answer. The correct syntax for creating a PDO object that uses a Windows Data Sources ODCB connection is not what I showed, but instead this (minus the try/catch):
$myConn = new PDO('odbc:TheBigDB','BigDBUser','myPwd');
BUT... with PHP 5.4.12 using ODBC to touch an Oracle 11 DB, you need to edit the correct php.ini file (see this WampServer forum topic for a discussion of which of three php.ini files you need to edit). Under Dynamic Extensions, uncomment extension=php_pdo_odbc.dll and extension=php_pdo_oci.dll (I did both; not sure which one did the trick...)
Another tip: In my scripts, neither odbc_connect() nor PDO() worked for me unless my connection was created in Windows Data Sources Administrator under the System DSN tab. It did not work under User DSN.

ADODB Connection Problem

I am trying to perform a database operation from a VB 6.0 application (connecting to SQL 2000). The application is running fine in my local and test machines, but it gives the following error in the UAT environment.
dbConn - Nothing
lErrorNum = -2147024770
sErrorDesc = Method '~' of object '~' failed
My source code is:
Dim connectionString As String
connectionString = "DSN = {My DSN Name}"
Private dbConn As ADODB.Connection
Set dbConn = New ADODB.Connection
With dbConn
.ConnectionString = sConn
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.CommandTimeout = 60
.Open
End With
The MDAC version is MDAC 2.8 SP2 ON WINDOWS SERVER 2003 SP1. (Check with CompChecker)
I have copied the source code to the UAT environment and tried running it from the IDE, but still the same error.
One possibility is that you need to install the MS SQL Client tools on the UAT server (http://msdn.microsoft.com/en-us/library/aa197918(SQL.80).aspx). Have you checked the DSN itself using the test connection option? You could also try an DSN-less connection string.
The error code is a Win32 facility error, 123 ERROR_INVALID_NAME: The file, directory name, or volume label syntax is incorrect.
Sounds like ADO isn't installed correctly.

Resources