在此 C# 代码中连接不断超时:
private const string _connectionString = "User Id=c##BookingApp;Password=ftn;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xe)))";
public static void Test()
{
using (OracleConnection con = new OracleConnection(_connectionString))
{
try
{
con.Open();
OracleCommand com = con.CreateCommand();
com.CommandText = "SELECT * FROM user_tb;";
com.ExecuteToStream(System.IO.Stream.Null);
con.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
这是
lsnrctl status
的输出:
LSNRCTL for 64-bit Windows: Version 21.0.0.0.0 - Production on 25-MAR-2024 10:42:12
Copyright (c) 1991, 2021, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=DESKTOP-08F6LQM)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 21.0.0.0.0 - Production
Start Date 15-MAR-2024 15:56:49
Uptime 9 days 18 hr. 45 min. 23 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File C:\app\PC\product\21c\homes\OraDB21Home1\network\admin\listener.ora
Listener Log File C:\app\PC\product\21c\diag\tnslsnr\DESKTOP-08F6LQM\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DESKTOP-08F6LQM)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=DESKTOP-08F6LQM)(PORT=5500))(Security=(my_wallet_directory=C:\APP\PC\PRODUCT\21C\admin\XE\xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "7c74ac5f71294090a35b32d2635fdfc9" has 1 instance(s).
Instance "xe", status READY, has 2 handler(s) for this service...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XE" has 1 instance(s).
Instance "xe", status READY, has 2 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
Instance "xe", status READY, has 1 handler(s) for this service...
Service "xepdb1" has 1 instance(s).
Instance "xe", status READY, has 2 handler(s) for this service...
The command completed successfully
我已经尝试了连接字符串的每种变体,但我无法弄清楚为什么它超时。 SQL Developer 中的连接工作正常。
我正在使用
Oracle.ManagedDataAccess.Client
并且我看到有人提到 Oracle.DataAccess.Client
但我找不到合适的软件包,所以我假设这只是 ManagedDataAccess
软件包的旧版本。
您正在连接到:
(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xe))
但你的听众正在听:
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=DESKTOP-08F6LQM)(PORT=1521)))
我假设 DESKTOP-08F6LQM 未映射到 127.0.0.1。此外,当连接到 Express Edition 时,您通常会在可插入数据库 XEPDB1 中完成所有工作,因此您通常会连接到该数据库,而不是 XE