c# - 尝试连接到 Oracle 数据库时出现 "ORA-01012"错误消息

标签 c# oracle10g odp.net

使用 C# 和 Oracle Data Provider for .NET (ODP) 我对数据库进行了长时间查询,然后使用 TOAD 在服务器端结束了连接。之后,后续调用数据库,甚至创建一个新的OracleConnection对象,都会抛出如下错误:

ORA-01012: not logged on
Process ID: xxx
Session ID: yyy Serial number: zzz

其中 Process ID 和 Session ID 是我用来结束连接的标识符。

好像当我在服务器端结束与Oracle数据库的连接时,断开的连接返回到连接池。并且当 C# 客户端代码(使用 ODP)打开新连接时,可能会检索返回到连接池的断开连接。

关于如何解决此行为的任何想法?

顺便说一句,我正在使用 Oracle 客户端 10

最佳答案

我通过将连接字符串中的“Validate Connection”属性设置为 true 解决了我的问题。

您可以阅读更多here

作为警告,我引用了 Oracle 文档。

The Validate Connection attribute validates connections coming out of the pool. This attribute should only be used when absolutely necessary because it causes a server round-trip to the database to validate each connection right before it is provided to the application. If invalid connections are uncommon, developers can create their own event handler to retrieve a new connection, rather than using Validate Connection. This generally provides better performance.

关于c# - 尝试连接到 Oracle 数据库时出现 "ORA-01012"错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11022111/

相关文章:

sql - 如何将表别名传递给 SQL 中的子子查询?

c# - PLS-00306 : wrong number or types of arguments error in C#

c# - "Connection must be open for this operation"ODP异常

c# - 按进程获取电池使用情况

oracle - 仅更改外部表 BADFILE、LOGFILE 和 DISCARDFILE 参数

c# - LINQ 包含追加 % 和转义 %

sql - 如何在不区分大小写的 Oracle DB 中返回不同的记录?

c# - 将 System.Data.OracleClient 替换为 Oracle.DataAccess (ODP.NET)

c# - C# 中多重继承的替代解决方案的最佳实践是什么

c# - 密码输入字段审查 (****) - 记录和注册