使用 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/