Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the handling of blanks in manually configuring tnsnames.ora files

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail for you how to understand the manual configuration of tnsnames.ora files to deal with blank matters, the content of the article is of high quality, so the editor shares it for you to do a reference, I hope you have a certain understanding of the relevant knowledge after reading this article.

There are basically two ways to configure database connection strings: one is to use the graphical tool netmgr; and the other is to edit and modify the network configuration file tnsnames.ora directly by hand.

These two configuration methods have their own advantages and disadvantages. Because the netmgr tool configuration method needs to start the graphical interface, it is more limited by the environment. The advantage is that the information configured using netmgr is not prone to errors; manual configuration of tnsnames.ora is suitable for experienced DBA use, and the advantage is that it can be done on the command line, fast and efficient, and the disadvantage is error-prone.

Give a case where manual configuration of tnsnames.ora is extremely error-prone: careful handling of spaces!

1. Standard tnsnames.ora content

Ora10g@secdb / home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora

……

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

……

The standard configuration shows the configuration of the connection string in exquisite indentation, which is easy to read.

It is recommended to use this as a template to configure other connection strings.

two。 Other forms of configuration

1) No indentation form

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

The above form of writing is not indented, so its readability is greatly reduced. But this form is feasible.

What needs to be reminded here is that the connection string name needs to be written at the head, and the head writing of other content is not allowed in the definition of the database connection string except the beginning and end parentheses! (there will be an error example later)

2) one line takes care of everything

ORA10G= (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=secdb) (PORT=1521)) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=ora10g)

This is the most streamlined configuration, but the disadvantage is obvious: it is difficult to sort out grammatical relationships quickly. This configuration method can be integrated into the script to quickly edit the tnsnames.ora configuration file in the test environment.

3. Handle spaces carefully

The configuration rule has been given in the above "non-indented form": the connection string name needs to be written at the head, and the head writing is not allowed except for the parentheses in the definition of the database connection string.

For example, the following configuration is not feasible.

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

Note that head writing on the penultimate line above is not allowed!

And so on, the following writing formats are also illegal.

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

ORA10G =

(DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP) (HOST = secdb) (PORT = 1521))

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = ora10g)

)

)

The error message when connecting to the database is as follows:

Ora10g@secdb / home/oracle$ sqlplus sec/sec@ora10g

SQL*Plus: Release 10.2.0.3.0-Production on Fri Dec 17 21:10:16 2010

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

ERROR:

ORA-12154: TNS:could not resolve the connect identifier specified

Enter user-name:

If conditions permit, you can use the netmgr tool to configure the database connection string, which can avoid errors caused by manually writing the configuration file. For experienced friends, it is recommended to use manual configuration, after all, it is more transparent and efficient.

On how to understand the manual configuration of tnsnames.ora files to deal with space issues to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report