TNS Listener error - sql

I've installed Oracle 11g and now I'm getting the following error when I try to connect with PL-SQL Developer
ORA-12154: TNS:could not resolve the
connect identifier specified
How do I check what 'identifier' is specified?
There are two TNS listeners in my services now but only the 11g can start because the 9i directory does not exist anymore.
Anyone know a solution?
My tnsnames.ora
ORCL = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = XXX_L07082.xxx-batt.local)(PORT =
1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
) )
My listner.ora
LISTENER = (DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = XXX_L07082.xxx-batt.local)(PORT = 1521))
) )
sqlnet.ora
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES,
EZCONNECT)
TNSPING ORCL
Attempting to contact (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =
XXX_L070
82.xxx-batt.local)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_N AME = orcl))) OK (40 msec)

Do you have multiple Oracle clients installed at the same time?
Unfortunately, if you install multiple versions of the Oracle client, they sometimes (maybe often?) don't work well together. What is probably happening is that some of the paths are getting mixed between the two versions of the Oracle client. I would remove the older one.
What happens if you type in: tnsping [name]
Maybe tnsping will give you some more useful information.
In Windows, I have fixed these sorts of problems before by editing the PATH environment variable, and removing all references to the old Oracle client. You can edit the PATH environment variable by going to Computer -> Properties -> Advanced System Settings (Vista and 7 only) -> Advanced (tab) -> Environment Variables... I usually copy out the path and edit it in notepad, then copy the edited path back in.
If this doesn't work and the directory structure for the old client exists, then I would copy the tnsnames.ora into the Network/Admin directory of the old client to see if that works.

Related

How to read/fetch data from Oracle SQL database using PowerShell Core?

I have been researching on this for a couple of days but have been going in circles here.
I need to write a script that fetches the data from Oracle db and do something with the data. In my script I will have to fetch data multiple times.
My machine has the SQLDeveloper-21.4.3 which I got from installing InstantClient-Basic-Windows-21.3.0. I use the SQL Developer to connect to the db which is on another machine; this is how I can look into tables, views etc. of the db.
Secondly, this script will be hosted on another server that runs Windows-Server-2012-R2. I am just using my machine to write the script because I cannot use the server to do this. Therefore, I am looking for a solution that requires minimum amount of installing.
Thirdly, we do not have Oracle commercial license. This Oracle db I am trying to access is on the machine installed by a third party that installed some instruments. This company uses Oracle as they collect data on the instruments installed.
I was hoping the solution would be something similar to invoking connection to MS SQL where I downloaded module that gave cmdlets to connect to the MS SQL.
Oracle does have Oracle Modules for PowerShell but neither have I found information on how to use them nor have I understood the little information provided by Oracle on this. For this to work one of the requirement is:
A configuration file and key pair used for signing API requests, with
the public key uploaded to Oracle Cloud using Oracle Cloud
Infrastructure Console. Only the user calling the API should possess
the private key.
I don't know the heck Oracle is talking about here. Like, what is this configuration file, where is it? Where would I get the key pair from for signing API request. What is Oracle Infrastructure Console, where do I get it from? You get the idea.
Link: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/powershell.htm
Therefore, I went the .DLL route.
This is what I have done so far:
I installed Oracle.ManagedDataAccess.Core -Version 3.21.61 from NuGet.
Unzipped the package and moved the Oracle.ManagedDataAccess.dll to the location of my script.
The code is:
$OracleDLLPath = "C:\Users\Desktop\CNC_File_Transfer_VSCode\Fastems_NicNet\Oracle.ManagedDataAccess.dll"
$datasource = " (DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = 10.50.61.9)(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED)
(SERVICE_NAME = Fa1)
(FAILOVER_MODE = (TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5))))"
$username = "username"
$password = "password"
$queryStatment = "SELECT [PROG_TYPE] FROM NC_PROGRAMS FETCH FIRST 10 ROWS ONLY"
#Load Required Types and modules
Add-Type -Path $OracleDLLPath
Import-Module SqlServer
Write-Host $queryStatment
#Create the connection string
$connectionstring = 'User Id=' + $username + ';Password=' + $password + ';Data Source=' + $datasource
#Creates a data adapter for the command
$da = New-Object Oracle.ManagedDataAccess.Client.OracleDataAdapter($cmd);
#The Data adapter will fill this DataTable
$resultSet = New-Object System.Data.DataTable
#Only here the query is sent and executed in Oracle
[void]$da.fill($resultSet)
#Close the connection
$con.Close()
WRITE-HOST $resultSet
This gives an error though:
Add-Type : Unable to load one or more of the requested types. Retrieve
the LoaderExceptions property for more information.
I am new to programming in general. I would really appreciate if someone could provide detailed steps on resolving this. Thanks in advance.

VB.NET: Unable to connect to an Oracle database server from client app

I have 2 laptops (A and B) on the same local networks (Wi-Fi).
I have installed Oracle database 12c r2 on laptop A.
In laptop A I have created a VB.NET application with Visual Studio 2017 that can connect to the Oracle database.
The app works fine on laptop A. It connects to the database and this is my app form, and the connection string I use (192.168.20.98 is my laptop A IP Address):
oracle_connection = New OracleConnection(
"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=" & protocol.Text &
")(HOST=" & host.Text & ")(PORT=" & port.Text &
")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & db_name.Text &
")));User Id=" & user_id.Text & ";Password=" & pswd.Text)
I've also edited my listener.ora and tnsnames.ora located in C:\app\mustafa\product\12.2.0\dbhome_1\network\admin
as the following:
listener.ora:
# listener.ora Network Configuration File:
C:\app\mustafa\product\12.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\app\mustafa\product\12.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS =
"EXTPROC_DLLS=ONLY:C:\app\mustafa\product\12.2.0\dbhome_1\bin\oraclr12.dll")
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.98)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
tnsnames.ora:
# tnsnames.ora Network Configuration File:
C:\app\mustafa\product\12.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
DB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.98)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db1)
)
)
LISTENER_DB1 =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.20.98)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
I've edited my Oracle home folder permission to give authenticated users the full access.
So when I move my app to the laptop B and run it to connect to the database on laptop A I got this error:
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
I can't find any solution. Does it require the Oracle database 12c r2 to be installed on my laptop B too?
The System.Data.OracleClient namespace is the .NET Framework Data Provider for Oracle, but still it needs the Oracle Client software installed on the target machine:
Oracle and ADO.NET | Microsoft Docs
The .NET Framework Data Provider for Oracle provides access to an Oracle database using the Oracle Call Interface (OCI) as provided by Oracle Client software.
And:
.NET Framework Data Providers | Microsoft Docs
For Oracle data sources. The .NET Framework Data Provider for Oracle supports Oracle client software version 8.1.7 and later, and uses the System.Data.OracleClient namespace.
But, as stated on the docs also:
Note
The types in System.Data.OracleClient are deprecated. The types remain supported in the current version of.NET Framework but will be removed in a future release. Microsoft recommends that you use a third-party Oracle provider.
So, it's better to use the Oracle Data Provider for .NET (ODP.NET), instead of the deprecated System.Data.OracleClient. Here there's a 3 steps migration article to help in the proccess.
Anyway, both the Microsoft or Oracle data providers will still require the Oracle Client software installed on the target machine. The Oracle Client software is named Oracle Instant Client and can be found here.
If you already have the Oracle Instant Client installed on the target machine, you could try one of these (that I think the question's author already did):
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater - Fadi Abdulwahab's Blog
vb.net - System.Data.OracleClient requires Oracle client software version 8.1.7 - Stack Overflow

Oracle ADF DataSource for RAC environment

I have environment of Oracle database 11gR2 Single Instance on linux, Weblogic 10.3.5 on Windows. I have running ADF Application with single instance database. The Connection between Database and Application is configured by using Generic DataSource "MyAppDS".
On Other side i Have Configured new RAC Database environment with same Application. the Connection between RAC database and Application is configured by using GridLink DataSource. the Confusion is about the JDBC/MyAppDS. Is this should be same or different for RAC. Should the Developer have to create new connection string for RAC database.? kindly help
We recommend using JDBC Thin driver with Oracle RAC. Most of our customers are using JDBC Thin driver. Active Grid Link is the correct datasource to use with WLS. Sample RAC URL is as shown below. Always use SCAN for better manageability purposes.
jdbc:oracle:thin:#(DESCRIPTION =
(CONNECT_TIMEOUT= 90) (RETRY_COUNT=20)(RETRY_DELAY=3)
(ADDRESS_LIST =
(LOAD_BALANCE=on)
(ADDRESS = (PROTOCOL = TCP)(HOST=primary-scan)(PORT=1521)))
(ADDRESS_LIST =
(LOAD_BALANCE=on)
( ADDRESS = (PROTOCOL = TCP)(HOST=secondary-scan)(PORT=1521)))      
(CONNECT_DATA=(SERVICE_NAME = gold-cloud)))
The JNDI name can be the same, as long as the other one pointing to the single instance change from JDBC/MyAppDS to something else, let's say JDBC/MyAppDSOld.
The URL should be something like the following:
jdbc:oracle:oci:#(DESCRIPTION = (LOAD_BALANCE = ON) (FAILOVER = ON)
(ADDRESS =(PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 1521))
(ADDRESS =(PROTOCOL = TCP)(HOST = 10.10.10.11)(PORT = 1522))
(CONNECT_DATA =(SERVER = DEDICATED) (SERVICE_NAME = xxxx) (FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 2))))
The Developer should use the GridLink for RAC Datasource type when creating the connection, to take advantage of Oracle ONS, TAF and Load Balancing to multiple database instances.
For a more detailed information on transactions, XA, etc. Take a look here.
Hope it helps !

Using variables within a SQL*Plus connect string

I have a SQL*Plus routine embedded inside of a KornShell (ksh) script.
As long as I hard code my SID in the connect string, the entire routine works as intended.
However, depending on whether I am in debug mode, or production mode, will depend on which SID I want to connect to.
When I attempt to use a variable in place of the hardcoded SID, inside of the connect string, it continually errors out.
I have tried single quotes, double quotes, braces, back-slashing the $, etc.
But, nothing that I have tried, short of hardcoding the SID in this connect string seems to work.
Here is an example of my connect string:
sqlplus UserID/"Passwd"#(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HostID)(PORT = Port))(CONNECT_DATA = (SID = $ORASID)))
Remember that it works, if I simply hardcode the SID:
sqlplus UserID/"Passwd"#(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HostID)(PORT = Port))(CONNECT_DATA = (SID = OraSID)))
Can anyone tell me how I can get the SID to work as a fed-in variable?
Thanks in advance.
This works for me:
sqlplus -s $user/$password#$SID
and so does this:
sqlplus -s $myLogin
where $myLogin = user/password#SID

Oracle 11gr2 connection to Sql Server using dg4msql problem

To whom it may respond to,
We have installed Oracle 11g r2 on a Redhat Enterprise Linux 5.4 . We are trying to connect to a Sql Server 2005, after applying some notes the error below is the result we got :
"ORA-28513 internal error in heterogenous remote agent".
listener.ora is as below :
[oracle#oracledb admin]$ less listener.ora
)
(SID_DESC =
(SID_NAME = dg4msql)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(PROGRAM = dg4msql)
(ENVS=LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/db_1/dg4msql/lib:/u01/app/oracle/product/11.2.0/db_1/lib)
)
)
LOGGING_LISTENER = on
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracledb)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
TRACE_LEVEL_LISTENER = on
tnsnames.ora is as below :
[oracle#oracledb admin]$ less tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
fasdat =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = oracledb)(PORT = 1521))
)
(CONNECT_DATA =
(SID = fasdat)
)
)
dg4msql =
(DESCRIPTION =
(ADDRESS =
(PROTOCOL= TCP)
(HOST = oracledb)
(PORT = 1521)
)
(CONNECT_DATA=
(SID=dg4msql) )
(HS=OK))
init4msql.ora is as below :
[oracle#oracledb admin]$ less initdg4msql.ora
# This is a customized agent init file that contains the HS parameters
# that are needed for the Database Gateway for Microsoft SQL Server
#
# HS init parameters
#
HS_FDS_CONNECT_INFO=192.168.1.48:1433//NAVISION
# alternate connect format is hostname/serverinstance/databasename
#HS_FDS_TRACE_LEVEL=0
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
#HS_LANGUAGE=turkish_turkey.WE8ISO8859P9
HS_NLS_NCHAR=WE8ISO8859P9
#HS_FDS_TRACE_LEVEL=DEBUG
We have setup a system dsn at Sql Server 2005 named 'dg4msql' , chose the driver as 'Sql Server' and server as 'local'
We would be glad to hear any ideas to resolve this problem,
You seem to be using the Gateway for MySQL set-up rather than the Heterogeneous Gateway (for ODBC connections). Here is an overview of the process
On SQL Server create a database user and give it read access to the database/tables you want to read via the Oracle database link.
In the gateway home each SQL Server database you want to access should have an init.ora
located in $OH/dg4msql/admin in the form initsid.ora where sid is the name of
the database to be used in the link (e.g. initbob.ora), so create one
HS_FDS_CONNECT_INFO=msserver1:1234//Example_Database
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
HS_TRANSACTION_MODEL=READ_ONLY
You must now add the new sid to the listener.ora in the gateway home using an additional SID_DESC section inside the existing SID_LIST, for example
(SID_DESC =
(SID_NAME=bob)
(ORACLE_HOME=/oracle/gateway/product/11.2.0)
(ENVS=LD_LIBRARY_PATH=/oracle/gateway/product/11.2.0/dg4msql/driver/lib;/oracle/gateway/product/11.2.0/lib)
(PROGRAM=dg4msql)
)
You should now stop and restart the gateway listener so that the new sid becomes
active. NB a reload is not enough.
You must now add the new sid in the tnsnames.ora file for the listener of each
database in which you will create a link. You don't need to do this in the gateway home unless it is also a database home in which you will create a database link.
bob =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = severname.example.com)(PORT = 1690))
(CONNECT_DATA = (SID = bob))
(HS = OK)
)
NB: The host and port are for the gateway not for the SQL Server database
In each database that requires a link to the MS-SQL database you should create a database link to your new gateway sid.
CREATE PUBLIC DATABASE LINK bob
CONNECT TO "ms_user" IDENTIFIED BY "ms-passwd" USING 'bob';
where ms-user and ms-password are the SQL Server user you created right at the start.
Now you can test the new database link
SELECT COUNT(*) FROM "Table_Name"#bob;
Once you have this working you can alter the initsid.ora file to add parameters to suit your connection. If you do it this way you can easily add and manage many different databases via the gateway.