我正在尝试使用PHP中的ODBC访问Oracle数据库。 (Apache 2,PHP 5,ODBC驱动程序和Oracle数据库11.2安装在VirtualBox中的Ubuntu Server 14.04上。)
我已经设法安装了Oracle数据库,我想我已经配置了tnsnames.ora和ODBC驱动程序:
但是当我在PHP中调用odbc_connect时,我收到以下错误:
警告:odbc_connect():SQL错误:[unixODBC] [Oracle] [ODBC] [Ora] ORA-12514:TNS:侦听器当前不知道连接描述符中请求的服务,/ var中的SQLConnect中的SQL状态S1000第61行/www/html/index.php
我相信驱动程序运行正常,因为它在错误中提到过。当我尝试在没有安装驱动程序的情况下调用odbc_connect
时,我又出现了另一个错误。
如果我在使用sqlplus时指定@DB
,我会收到一些奇怪的错误(那里的列表)。
这是tnsnames.ora的配置方式:
# tnsnames.ora Network Configuration File:
MYNAME =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = database)(PORT = 1521))
)
(CONNECT_DATA = (SID = XE))
)
DB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = database)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
我开始时 DB
和EXTPROC_CONNECTION_DATA
部分在这里,但我还添加了MYNAME
来测试我是否应该使用(CONNECT_DATA = (SID = XE))
代替(SERVICE_NAME = ORCL)
。< / p>
我无法像sqlplus dbuser@DB
sqlplus dbuser@DB
SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 17 21:22:41 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-12641: Authentication service failed to initialize
如果我将SQLNET.AUTHENTICATION_SERVICES
从ALL
更改为NONE
,我将无法使用sqlplus登录:
sqlplus dbuser@DB
SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 17 21:22:41 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
sqlplus dbuser
SQL*Plus: Release 11.2.0.2.0 Production on Wed Feb 17 21:22:41 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
Process ID: 0
Session ID: 0 Serial number: 0
ORA 12514 error:TNS listener error
- 检查数据库实例是否已启动并正在运行
- 检查
lsnrctl service
命令的输出,看看注册了哪些服务。- 检查连接到实例时是否正确指定了
SERVICE_NAME
。- 如果在侦听器发生之前发生了数据库实例,有时您只需稍等一下,或者可以执行
醇>alter system register
以注册实例。
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
尝试了两种(local_listener
解决方案)。
所以我在tnsnames.ora中遗漏了一些东西?或者我遇到了一些其他问题?
lsnrctl status
:
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 18-FEB-2016 20:27:56
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 18-FEB-2016 20:21:31
Uptime 0 days 0 hr. 6 min. 25 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service ORCL
Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/database/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=database)(PORT=1521)))
Services Summary...
Service "ORCL" has 1 instance(s).
Instance "XE", status READY, has 1 handler(s) for this service...
Service "ORCLXDB" has 1 instance(s).
Instance "XE", status READY, has 1 handler(s) for this service...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
sqlplus dbuser
(当SQLNET.AUTHENTICATION_SERVICES
设置为ALL
时):
SQL*Plus: Release 11.2.0.2.0 Production on Thu Feb 18 20:26:50 2016
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL>
答案 0 :(得分:0)
我的/etc/odbc.ini
包含类似内容:
[DB]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle 12g ODBC driver
DSN = DB
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = localhost/DRORACLE
SQLGetData extensions = F
Translation DLL =
DisableRULEHint = T
UserID = dbuser
StatementCache=F
CacheBufferSize=20
我已将所有内容复制粘贴并编辑了几个键值对,以使其在我的机器上运行。
在过去的几天里,我在其他一些操作系统上使用Oracle数据库。例如,我从Oracle站点下载了Oracle DB Developer VM映像,其中数据库已经安装并且工作正常。
所以,我查看了odbc.ini
中的那条记录,并决定尝试一些更简单的方法(了解其他机器上的工作正常):
[DB2]
Driver = Oracle 12g ODBC driver
DSN = DB
ServerName = database
UserID = dbuser
Password = dbuser
我尝试isql -v DB2
并且它有效!
ODBC驱动程序给我错误的原因是 ServerName !
ServerName = localhost/DRORACLE
VS
ServerName = database
在我的情况下, database
== localhost
,只是/etc/hosts
中的另一行。
实际上,当我刚刚更改了第一条记录中的isql -v DB
时,我收到了来自ServerName
的错误消息,但这只是因为该记录缺少Password
字段。
我应该补充说我在这里使用SQLNET.AUTHENTICATION_SERVICES = (NONE)
。我不确定原因,但如果我在那里使用ORA-12641: Authentication service failed to initialize
,则会显示(ALL)
。对我来说无关紧要,所以你可能应该自己弄清楚,如果你要配置它。
答案 1 :(得分:0)
我承认我花了很长时间才找到解决方案,而对我来说,问题是远程服务器上的一个端口,由Windows管理员重定向。即使本地服务器上的Oracle DB端口很难设置为1522,这个端口也被重定向用于远程连接,而且它是不同的!因此,如果您已验证所有连接数据似乎正确,请联系您的服务器/网络管理员并要求端口(1522/1521 / oracle db)重定向。