我们有一个本地运行的应用程序,我们遇到了以下错误:

ORA-12514: TNS:监听器当前不知道所请求的服务 在连接描述符中

我已经使用正确解决的tnspring测试了连接 我尝试使用SQLPlus进行连接,但失败了,出现了与上面相同的错误。我在SQLPlus中使用了以下语法:

sqlplus username/password@addressname[or host name]

我们已核实:

服务器上的TNS Listener正在运行。 服务器上的Oracle本身正在运行。

我们不知道这个环境发生了什么变化。 还有什么可以测试的吗?


当前回答

对于那些可能在虚拟机中运行Oracle的人(比如我),我看到这个问题是因为我的虚拟机内存不足,这似乎阻止了OracleDB正确启动/运行。增加我的虚拟机内存和重新启动修复了这个问题。

其他回答

对于Dbeaver用户:尝试在连接设置中选择“SID”而不是“服务名称”。

检查数据库是否启动。登录到服务器,将ORACLE_SID环境变量设置为您的数据库SID,并作为本地连接运行SQL*Plus。

这里有很多答案,但这里有一个工作示例的代码,你可以立即复制、粘贴和测试:

对我来说,在指定正确的SERVICE_NAME后,错误12514得到了解决。 您可以在服务器上的文件tnsnames中找到它。ora自带3个预定义的服务名称(其中一个是“XE”)。

I installed the Oracle Express database OracleXE112 which already comes with some preinstalled demo tables. When you start the installer you are asked for a password. I entered "xxx" as password. (not used in production) My server runs on the machine 192.168.1.158 On the server you must explicitely allow access for the process TNSLSNR.exe in the Windows Firewall. This process listens on port 1521. OPTION A: For C# (.NET2 or .NET4) you can download ODAC11, from which you have to add Oracle.DataAccess.dll to your project. Additionally this DLL depends on: OraOps11w.dll, oci.dll, oraociei11.dll (130MB!), msvcr80.dll. These DLLs must be in the same directory as the EXE or you must specify the DLL path in: HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.112.4.0\DllPath. On 64 bit machines write additionally to HKLM\SOFTWARE\Wow6432Node\Oracle\... OPTION B: If you have downloaded ODAC12 you need Oracle.DataAccess.dll, OraOps12w.dll, oci.dll, oraociei12.dll (160MB!), oraons.dll, msvcr100.dll. The Registry path is HKEY_LOCAL_MACHINE\SOFTWARE\Oracle\ODP.NET\4.121.2.0\DllPath OPTION C: If you don't want huge DLL's of more than 100 MB you should download ODP.NET_Managed12.x.x.x.xxxxx.zip in which you find Oracle.ManagedDataAccess.dll which is only 4 MB and is a pure managed DLL which works in 32 bit and 64 bit processes as well and depends on no other DLL and does not require any registry entries. The following C# code works for me without any configuration on the server side (just the default installation):

using Oracle.DataAccess.Client;
or
using Oracle.ManagedDataAccess.Client;

....

string oradb = "Data Source=(DESCRIPTION="
    + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.158)(PORT=1521)))"
    + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));"
    + "User Id=SYSTEM;Password=xxx;";

using (OracleConnection conn = new OracleConnection(oradb)) 
{
    conn.Open();
    using (OracleCommand cmd = new OracleCommand())
    {
        cmd.Connection  = conn;
        cmd.CommandText = "select TABLESPACE_NAME from DBA_DATA_FILES";

        using (OracleDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                listBox.Items.Add(dr["TABLESPACE_NAME"]);
            }
        }
    }
}

如果SERVICE_NAME=XE错误,则会得到错误12514。SERVICE_NAME是可选的。你也可以把它放在一边。

我也遇到过同样的问题,花了3天时间才把它挖出来。

发生这种情况是因为您错误的TNS服务条目。

首先检查是否能够使用sql > sqlplus sys@orastand作为sysdba (orastand是一个备用数据库)从主数据库连接到备用数据库。

如果您无法连接,那么这是与服务的问题。更正主端TNS文件中服务名称的填写。

用同样的方法检查备用数据库。如果需要,也可以在这里进行更改。

确保log_archive_dest_2参数具有正确的服务名称。

我的问题解决了,用“服务名称”和正确的主机替换URL中的“sid”。