我们有一个 32 位 .Net windows 应用程序,它使用 ODAC 10g (1.x) 连接到后端的 10g 数据库。在此部署中一切正常。
我们正在建立一个新的开发机器。这台机器上安装了 ORACLE 11g(64 位)。我们在连接数据库时遇到问题。
这是我们用来连接数据库的代码块:
dataString = "user id=xxx;password=\"xxx\";data source=localhost:1521/ORCL";
using (OracleConnection oraconn = new OracleConnection(dataConn))
{
oraconn.Open();
Oracle.DataAccess.Client.OracleCommand cmd = new OracleCommand(sOraSQL, oraconn);
cmd.CommandType = CommandType.Text;
Oracle.DataAccess.Client.OracleDataAdapter da = new OracleDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
oraconn.Close();
return dt;
}
“oraconn.Open()”命令出现异常。
ora-12514: TNS: 侦听器当前不知道连接描述符中请求的服务
TNSNAMES.ORA 文件如下所示:
# tnsnames.ora Network Configuration File: C:\app\DjM\product\11.2.0\dbhome_1 \network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.168.1.100)
)
)
这是 SQLNET.ORA 文件的样子:
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES = (NTS)
这是连接字符串的样子:
"user id=xxx;password=\"xxx\";data source=localhost:1521/ORCL"
笔记::
我们能够运行 SQLDeveloper 并指向相同的 SID (ORCL),我们可以很好地连接到数据库实例。
我们还能够在原始机器上安装 11g 32 位 ODAC,它在那里运行良好。
这必须是与 tnsnames 相关的配置或类似的东西。