tnsping 无法识别里面的换行 tnsnames.ora

tnsping cannot identify the line feed inside tnsnames.ora

我在我的电脑上安装了 oracle 客户端 WINDOWS.X64_193000_client_home。我设置了 tnsnames.ora 文件。当使用 tnsping 命令测试连接时,我发现当我将所有值都放在一行中时没有换行。

Name1 =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = xxx)(SERVER = DEDICATED)))

但是如果我用换行符将值放在几行中,它会抛出错误。

Name1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = x.x.x.x)
(SERVER = DEDICATED)
)
)

错误如下

PS C:\Oracle\WINDOWS.X64_193000_client_home\network\admin> tnsping sap TNS Ping Utility for 64-bit Windows: Version 19.0.0.0.0 - Production on 03-MAY-2022 16:33:13

Copyright (c) 1997, 2019, Oracle. All rights reserved.

Used parameter files: C:\Oracle\WINDOWS.X64_193000_client_home\network\admin\sqlnet.ora

Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = TNS-12533: TNS:illegal ADDRESS parameters

如何让它识别换行?

编辑: 一些答案是关于 tnsnames.ora 文件的不正确内容。是的,在我用一些缩进更改 tns 后,它正在工作。

但是我也在我的电脑上安装了Oracle SQL Developer。使用tns正常,可以成功连接oracle服务器

试试这个:

Name1 =
 (DESCRIPTION =
   (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
     (ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
     (ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
     (ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = 1521))
   )
   (CONNECT_DATA =
     (SERVICE_NAME = x.x.x.x)
     (SERVER = DEDICATED)
   )
 )

我找到这个 Syntax Rules for Configuration Files:

Oracle Corporation recommends that you set up the files so that indentation reflects what keyword is the "parent" or "owner" of other keyword-value pairs. This format is not required, but it does make the files much easier to read and understand. This is the format that Network Manager generates.

Even if you do not choose to indent your files in this way, you must indent a wrapped line by at least one space, or it will be misread as a new parameter. The following layout is acceptable:

(ADDRESS=(COMMUNITY=tcpcom.world)(PROTOCOL=tcp)
  (HOST=max.world)(PORT=1521))

The following layout is not acceptable:

(ADDRESS=(COMMUNITY=tcpcom.world)(PROTOCOL=tcp)
(HOST=max.world)(PORT=1521))

Further Syntax Rules for TNS Configuration Files

The following rules apply to the syntax of configuration files:

  • Any keyword in a configuration file that should be recognized as beginning a parameter that includes one or more keyword-value pairs must be in the far left column of a line. If it is indented by one or more spaces, it is interpreted as a continuation of the previous line.