“无效的连接字符串格式"尝试使用包含点字符的TNS别名连接到Oracle时出错 [英] "Invalid connection string format" error when trying to connect to Oracle using TNS alias that contains dot character
问题描述
我正在尝试使用TNS连接到Oracle数据库.
I am trying to connect to Oracle database using TNS.
问题是TNS别名包含点,因此当我这样指定url时:
The problem is that TNS alias contains dot, so when I am specifying url like this:
jdbc:oracle:thin:@TNS.ALIAS
我有...
oracle.net.ns.NetException: Invalid connection string format, a valid format is: "host:port:sid"
...在建立连接期间.
...during creation of connection.
我知道点字符是一个问题,因为将其从tnsnames.ora
文件连接到数据库后就可以了.
I know that dot character is a problem, because after removing it from tnsnames.ora
file connection to database works.
我的问题是-是否可以以某种方式转义点字符?也许可以设置一些连接参数以允许使用点字符作为别名?我想避免从tnsnames.ora
中删除点,因为我是从外部源获取文件的.
My question is - is it possible to escape dot character somehow? Maybe there is some connection parameter that can be setup to allow dot character in alias? I would like to avoid removing dot from tnsnames.ora
since i am getting the file from outside source.
以下是我已经尝试过的选项,它们给了我同样的错误:
Here are the options that I've already tried that gave me the same error:
jdbc:oracle:thin:@"TNS.ALIAS"
jdbc:oracle:thin:@\"TNS.ALIAS\"
jdbc:oracle:thin:@`TNS.ALIAS`
jdbc:oracle:thin:@TNS\.ALIAS - this one is not compiling
jdbc:oracle:thin:@TNS\\.ALIAS
jdbc:oracle:thin:@TNS.ALIAS
jdbc:oracle:thin:@TNS\".\"ALIAS
jdbc:oracle:thin:@TNS%2eALIAS
以下是oracle.net.ns.NetException: could not resolve the connect identifier
产生的选项:
jdbc:oracle:thin:@TNSALIAS
jdbc:oracle:thin:@TNS-ALIAS
jdbc:oracle:thin:@TNS_ALIAS
其他上下文:
- 我正在尝试创建Java的
DataSource
(OracleDataSource
严格)在Scala中(它是Play框架-但我没有使用Play的 数据库连接的创建方式-我是手动完成的 - 我有一个使用完全相同的
tnsnames.ora
文件的SQL Developer,并且在那里工作 - 我们有C#应用程序正在使用完全相同的
tnsnames.ora
文件,并且在那里工作(数据源的定义如下:<add name="connectionName" connectionString="Data Source=TNS.ALIAS;"/>
- I am trying to create Java's
DataSource
(OracleDataSource
to be strict) in Scala (it is Play Framework - but I am not using Play's way of creation of DB connections - I am doing it manually) - I have SQL Developer that is using exactly the same
tnsnames.ora
file and it is working there - We are having C# applications that are using exactly the same
tnsnames.ora
file and it is working there (data source is defined like this:<add name="connectionName" connectionString="Data Source=TNS.ALIAS;"/>
推荐答案
我发现了问题-更改为较新的Oracle驱动程序(对于12.1.0.1
版本,使用的是ojdbc7.jar
版本,对于12.1.0.1
版本,使用了旧的Oracle驱动程序)版本12.2.0.1
)通过TNS别名的查找开始起作用-无需转义任何内容
I've found the problem - I was using older Oracle driver (ojdbc7.jar
for version 12.1.0.1
) after change to newer one (ojdbc8.jar
for version 12.2.0.1
) lookup by TNS alias started to work - there was no need to escape anything
这篇关于“无效的连接字符串格式"尝试使用包含点字符的TNS别名连接到Oracle时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!