使用C#和Oracle Data Provider for .NET(ODP)我对数据库进行了长时间的查询,然后使用TOAD结束服务器端的连接.之后,随后对数据库的调用,甚至创建新的OracleConnection对象,都会抛出以下错误:
ORA-01012: not logged on Process ID: xxx Session ID: yyy Serial number: zzz
进程ID和会话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.