Naked Oracle connections

Lightest-weight access to leading RDBMS

By Cameron Laird  Add a new comment

'Want to connect to Oracle without tnsnames.ora or sqlnet.ora?

I'll show you how.

As a developer, the main slices of time I spend with Oracle go to:

  • figuring out a configuration that gives me any sort of workable connection;
  • inferring the current data dictionary, and how it differs from the documented one; and
  • waiting for central administration to correct privileges that were already alleged to have been assigned.

Textbooks focus most on SQL coding, and schema and algorithm design, of course. While that's as it should be, it certainly doesn't reflect my on-the-job experience. Far too much of my time goes to tracking down basic connection configurations, often when the Oracle administrator has either moved on to another position, is completely backed up with emergency tasks, or is otherwise unavailable. The usual advice from co-workers starts with, "just use what's in tnsnames.ora ...", but you can imagine the problems with that: as a debugger or developer, I need to make changes, and the reference *.ora is inevitably the production one, which it would be unprofessional to modify.

Even when it is permissible to update *.ora, it's often inconvenient, or, more accurately, it's more convenient to maintain a complete test script or debugging configuration or development jig in a single file, rather than trying to synchronize several different "moving pieces"--a *.ora, a *.sql, and so on.

The good news, though, is that the widely-believed folklore about Oracle is false: it is possible to connect without *.ora. It's possible, if rather recondite, to fit everything on a single command-line. Here's an example from recent work of mine:

    sqlplus $ACCOUNT/$PASSWORD@'(DESCRIPTION=
                        (ADDRESS=(PROTOCOL=TCP)
                                          (HOST=$HOST)
                                          (PORT=1521))
                        (CONNECT_DATA=
                                          (SERVER=DEDICATED)
                                          (service_name=$SN)))'

Notice this is slightly stylized; in the real one, the $PAR-s are actually dereferenced, and there's no newline. Use of true variables introduces more subtleties beyond the scope of today's tip.

This is not new; the command-line ...@'...' interpretation has been possible for at least fifteen years. Many developers don't believe it exists, though, or are confused about the syntax. It's also timely to note that now, in 2010, developers can work with and learn essentially all database managers at no cost; all the vendors have no-charge versions available for development. The conclusion: don't wait for someone else to set you up to be productive with Oracle or other RDBMSs: you already have what you need.

ITworld LIVE

DevelopmentWhite Papers & Webcasts

Webcast On Demand

How to Distribute Apps to Your Mobile Workforce

When considering enterprise app deployment, you may find some unexpected challenges and a number of options that range from simple distribution to running your own enterprise market. How can you determine the best approach for your organization? MOTODEV for Enterprise can help you understand and evaluate current enterprise deployment technologies and learn best practices that support your choice.

Sponsor: Motorola Mobility

Webcast On Demand

Authentication, Certificates and VPNs

MOTODEV for Enterprise can help get you up to speed quickly on key topics such as how to enable secure access to a company intranet from outside the firewall. This webinar provides a clear explanation of terms and technologies and what they can do for your enterprise app development.

Sponsor: Motorola Mobility

Webcast On Demand

Improving Enterprise App Quality with MOTODEV App Validator

MOTODEV for Enterprise supports quality app development for businesses, government, and institutions with technical resources and tools such as the MOTODEV App Validator, a free static analysis testing tool.

Sponsor: Motorola Mobility

White Paper

HR Analytics: Driving Return on Human Capital Investments

In today's economy, it's critical for organizations to make employee retention and development a major business focus, to ensure that valuable employees are not lost as the economy improves. With advanced BI solutions, organizations can be supported by workforce analytics to drive return on human capital investment and to see the value the workforce delivers to organizational performance. This white paper demonstrates how the increased power of having metrics and analytic insight can align core HR business processes with organizational goals and strategies and help ensure organizations make the right business decisions today for tomorrow.

White Paper

Positioning the CIO as a Powerful Business Partner with IT Portfolio Governance

In this whitepaper, learn how you can become a visionary portfolio manager and transform IT into a streamlined revenue and profit center.

See more White Papers | Webcasts

Ask a question

Ask a Question