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

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

dawei

【声明】:北京站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。