Connect to an Oracle DB using ODBC - oracle

I am developing an application that needs to interract with a "lightly documented" Legacy Oracle Database. To Start that process I want to start creating a view into that Database using ODBC links into an MS Access database so I can figure out the DB structure but I can't figure out how to setup the ODBC connection to the Oracle DB.
I have been able to connect using the Host and Service Name to and view the DB using SQL Developer; but, I can't figure out how to setup ODBC. I am running Windows 7 and have installed Oracle 11g, Oracle Express Edition, the Instant Client and ODBC extensitons; but on the ODBC setup Oracle wants me to pick a TNS Service Name but there is none to pick and there is no place to specify the host. I tried to setup a TNS in tnsnames.ora; but I am not really sure I know the right location for that file.
I really thought this would be the easy part; but, it really hasn't been.

Navigate to the Control Panel > Administrative Tools > Data Sources (ODBC)
Select the System DSN tab and click 'Add'. Next scroll down the lists of drivers until you find Microsoft ODBC for Oracle.
Fill in the required information in the above form and click 'OK'. Now you can add the tables to 'Access' by clicking on the 'External Data' tab then clicking on 'More'. Choose 'ODBC Databases', then 'Import the source data...', next click on the 'Machine Data Source' tab.

The simplest option to generate the tnsnames.ora file is to let Oracle do it. If you launch the Oracle Net Configuration Assistant (Start | Oracle in Oracle Home Name | Configuration and Migration Tools | Net Configuration Assistant), you should be able to choose "Local Net Service Name configuration" which allows you to add (or modify) a TNS alias. That will walk you through gathering the information you'll need to connect.
If you are more comfortable dealing with the text files directly, you can directly edit the tnsnames.ora file in %Oracle Home%\network\ADMIN\tnsnames.ora using this as a template.
<TNS alias> =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = <hostname or IP>)(PORT = <port>))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = <database service name>)
)
)

In tnsnames.ora, try changing SERVICE_NAME to SID. That worked for me.

My Experience
1. TNSNAMES.ORA is as follows.
XE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = 192.168.2.116)
(PORT = 1521)
)
)
(CONNECT_DATA =
(SERVICE_NAME = XE)
)
)
Set Windows Environment Variables (ControlPanel --> System --> Detail..)
2-1. Add to PATH
c:\oraclexe\instantclient_11_2\ --- install directory of instantclient
2-2. Add New Environment Variable
TNS_ADMIN c:\oraclexe\instantclient_11_2\ --> install directory
NLS_LANG = JAPANESE_JAPAN.JA16SJISTILDE
Windows command prompt
cd c:\Windows\SysWow64 <--I use 32bit ODBC in 64bit Win7
odbcad32.exe
  Name : ICODBC <-- as you like
Service Name : XE
User Name: system
Press Connection Test Button

Related

Share Oracle Forms application on a local network

In my local network i have a server (Windows Server R2) and two computers with Windows 7, in my server i have Oracle database 10g and Oracle Forms and Reports 6i installed along with my forms application, i want to share my application on the network, and the best way i could think of is:
On the server:
Share the ORANT folder (C:\orant\).
Share the application folder (C:\app).
On the client computer:
Map a network drive for each folder, for example 'Y:' for 'orant' and 'Z:\' for 'app'.
make a shortcut on the desktop of "Y:\BIN\ifrun60.exe"
In the shortcut properties:
-The target is : Y:\BIN\ifrun60.EXE inicial.fmx
-Start in is: Z:\
I was wondering if that would work? Or do i have to do something else? is there a problem i should expect when doing this?
PS: it's for a client, and i can't test anything unless i'm sure of it.
The oracle runform client ifrun60.EXE needs a registry branch (it is necessary to copy the registry branch from the server) and also it is necessary to add paths to the PATH variable.
In order to share my application on the network, i followed the next steps:
Shared the application folder from the server.
Installed oracle forms and reports 6i on each client machine.
Created a shortcut to the ifrun60.exe with the starting form name (\server\app_dir\start.fmx) as the parameter and the application folder(\server\app_dir) as the start in.
Added this to the tnsnames.ora file in each orant directory of each machine :
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = server_IP )(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
and it worked perfectly!

Visual Studio 2013 and Oracle 11g express : how to connect?

I'm trying to reach my Oracle database through Visual Studio Server Explorer. I've installed Oracle 11g Express edition and I've downloaded the sql developer tool. By default, a "system user" is created and we've to give a password and I did it.
When it comes to connect to my DB via VS 2013, I choose the Oracle provider and I'm asked to enter the server name, the username and the password. I guess that the username and password are the system credentials but what about the server name? How can I find it? Is it XE by default? Because when I'm trying with that, I'm getting that error :
ORA-12154: TNS: could not resolve the connect identifier specified
Thanks for your help.
It's expecting an Oracle Net setup i.e. tnsnames.ora for clients and listener.ora for the server.
Use Oracle Net Manager to set these up.
Or simply use a thin driver and connect directly to the listener (usually port 1521)
http://www.oracle.com/technetwork/developer-tools/visual-studio/overview/index.html
Locate the Oracle XE EZ Connect settings
Find C:\APEX\XE\app\oracle\product\11.2.0\server\network\ADMIN\listener.ora where the path is the path you used to install Oracle XE as its root.
Open with Notepad and look for the HOST, PORT and DEFAULT SERVICE LISTENER settings. In this case, they are YOUR-HOST-NAME, 1521 and XE respectively.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = YOUR-HOST-NAME)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
Oracle Server Provider Settings In Visual Studio 2013
Visual Studio Server Explorer w/XE Added

Trying to connect Excel 2013 with Oracle - ORA-12154

I am trying to connect into Oracle through Power Query > From Database > From Oracle Database and then I type BI_TST, which is within my TNSNAMES (located in: C:\oracle\product\10.2.0\client_2\network\ADMIN), and has the connection below inside:
BI_TST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = srv-oracle3.mycompany.com.br)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bitst)
)
)
Also i have the variable path configured as TNS_ADMIN=C:\oracle\product\10.2.0\client_2\network\ADMIN.
When I use SQL Developer to connect, not using TNS put setting all the information manually, it works!
When I try to connect using TNS within Excel I get the error:
Message=ORA-12154: TNS:não foi possível resolver o identificador de conexão especificado
ErrorCode=-2146232008
Wich means in English: "could not resolve the connect identifier"
Could anyone please help me in this issue?
Thanks in advance!
Honestly, I've had my fill of tnsnames. I understand the idea behind it and can appreciate that, but I spend more time figuring out why it's not working than I do saving the extra keystrokes.
In my opinon, just bypass TNSnames use Oracle's ezconnect:
srv-oracle3.mycompany.com.br:1521/bitst
In place of:
BI_TST
This should work for ODBC as well. If you can't direct connect through PowerQuery's Oracle driver, try going through ODBC. While it's an additional layer you probably don't want, I doubt you'll notice a performance difference, and it may abstract the difficulties you normally have to deal with.
To clarify Hambone's response, to connect Excel to Oracle via Oracle client driver without using TNS Names:
Go to Control Panel > Administrative Tools > ODBC Data Sources
Go to File DSN tab
Choose Oracle driver (e.g. Oracle11gr1)
Provide a name for the new data source (any name)
When prompted for Service Name, enter host:port/servicename e.g. db123:1521/service123
Hope this works for everyone.

TNS:name lookup failure

I have a stand-alone workstation at work that connects to an oracle database. It's been working fine for years and then all of sudden I get an error:
[INTERSOLV][ODBC Oracle driver][Oracle]ORA-12545: TNS:name lookup failure
When I ping the server I am trying to connect to from the command prompt, it replies back with the right IP address. If I do a TNSPING, that seems to be ok as well.
I have a separate PC that is on the computer network and it connects to the server just fine - it doesn't have that error above in bold.
There is another, different oracle database that I connect to on that stand-alone PC and it's still working fine. So, it's not like I lost the ability to connect to any or all Oracle databases - just something about this one.
I'm confused why it won't work and haven't had any luck trying to fix it. I'm not sure how to proceed.
Any help would be appreciated.
Try defining the environment variable TNS_ADMIN to point at the location where your TNSNAMES.ORA file resides.
EDIT:
Can you connect with SQL*Plus directly?
If it's installed, this should work (replace user and db with the userid and database to conenct to):
sqlplus user#db
Failing that, try connecting with EZCONNECT:
Modify sqlnet.ora file:
NAMES.DIRECTORY_PATH=(TNSNAMES,EZCONNECT)
Change your ODBC Connection in the Oracle ODBC Driver Configuration wizard to use the EZCONNECT string:
Replace the TNS Service Name with:
<db_host>:port/<db_name>
e.g.,
MYHOST:1521/MYDB
This points to the database MYDB on host MYHOST at port 1521 (the default port).
Try testing the connection. If that fails, try using the IP address instead of the hostname.
Given your TNSNAMES entry from your comments:
ESTRNP = (DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ESTRNP)(PORT = 1521))
)
(CONNECT_DATA = (SID = ESTRNP))
)
You might try changing the CONNECT_DATA line to:
(CONNECT_DATA = (SERVICE = ESTRNP))
It is possible that the SID of the database was changed. Is this entry the same as the entry on the machine that works?
do you have recently install any other oracle software?
It is possible that you have multiple tnsnames.ora files on different locations and the odbc driver finds the wrong one.
Inspect you path environment variable, whether the path to the right one is at the first place.

Can't create Database Link to remote DB in Oracle-DB

We have a CRM system in our company, which uses an Oracle 11g database. It is developed by a third party vendor.
We do not have access to the server which runs the CRM system. But nevertheless, we have working DBA login data available to us (SYS user). It consists of:
server IP: 172.1.2.3
port: 1521
SID: abc
user: sys
password: *
We can use this to access the DB with Oracle SQL Developer 3.1 (Connections >> Properties)
Now parts of the data must be copied out of the CRM-database into an other Oracle database, which resides on another server.
To my understanding, I'd need to create a database link in my target database. I tried something like this:
CREATE PUBLIC DATABASE LINK xxx CONNECT TO sys IDENTIFIED BY ***** USING 'MYTNSENTRY'
My tnsnames.ora is as follows:
MYTNSENTRY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.1.2.3)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = abc)
)
)
.... and my listener.ora look like this:
MYLISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=172.1.2.3)(PORT=1521))
))
SID_LIST_MYLISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=MYTNSENTRY)
(ORACLE_HOME=C:\somepath) # path to Oracle home of target DB
(PROGRAM=extproc)))
Is PROGRAM=extproc the right choice? There are a couple of other programs to pick. I couldn't even start the listener with lsnrctl because it could not "verify the user" or something. Ironically, the listener-setup and database link to a MS SQL server work smoothly.
Now despite lacking some vital information about the CRM DB system, one can still connect to the DB in SQL Developer. Shouldn't it also be possible to make a connection between two Oracle DBs? Please help me with the setup and the creation of the database link.
----- EDIT: --------
Alex Poole's hint helped me get it to work. I used
show parameters service_names;
to get the full service name. It has the form abc.def, with def being the domain. Thusly, I added the domain name to the TNS alias in tnsnames.ora:
MYTNSENTRY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.1.2.3)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = abc.def)
)
)
The connection can be tested with tnsping MYTNSENTRY on the command prompt of the target DB server. The tnsnames.ora is local. However, I deleted all changes to the "local" listener.ora, since the listener indeed resides on the CRM server.
The SQL command is mostly unchanged, but now the connection works:
CREATE PUBLIC DATABASE LINK xxx CONNECT TO some_user IDENTIFIED BY ***** USING 'MYTNSENTRY'
You've said the SID is abc, but in your tnsnames.ora you've got the SERVICE_NAME in the CONNECT_DATA section. They are not always the same thing - see this question, or this Ask Tom entry. You haven't actually said what error you're getting, but just changing that to SID = might make a difference.
The listener.ora, and indeed the listener, are on the server that hosts the CRM database, not on the one that hosts your 'target' database. As you can connect from SQL Developer that is apparently already configured. The tnsnames.ora does need to be local.
But if you do know the service_name for the CRM database you can skip that and use the EZCONNECT syntax to define everything in the link:
CREATE PUBLIC DATABASE LINK xxx
CONNECT TO non-sys IDENTIFIED BY *****
USING '//172.1.2.3:1521/service_name';
Check your SQL Developer configuration to see if that is already using the service name, rather than SID, and if not you'll need to discover it. If you had access to the CRM server you could use lsnrctl to find the service names that are registered, but as you don't seem to you will need to connect to the database and run show parameters service_names or select value from v$parameter where name = 'service_names';.
You need more privileges to create a public link than a private one, and public is potentially less secure as it exposes your CRM database to anyone on your target one. So I'd only make it public if really needed, and either way connect to a read-only account if you're able to create one.
Also note that if your target database has global_names set to true the database link name has to match the remote service name.
Not only should you NOT connect as SYS unless necessary, you CANNOT connect as SYS over a database link.

Resources