且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Oracle ODP.Net和连接池

更新时间:2022-10-20 16:54:04

请查看以下一些结果:

对于问题一:(应用程序仍使用旧的数据库密码连接)

如果使用连接池选项连接数据库,则连接池管理器将在首次调用OracleConnection对象的openclose时创建并维护连接会话数. (此连接会话的数量取决于连接字符串中最小"和最大"池的大小).在Oracle中,我认为您可以像这样检查活动会话:

SELECT s.inst_id,
       s.sid,
       s.serial#,
       p.spid,
       s.username,
       s.program
FROM   gv$session s
       JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != 'BACKGROUND';

根据Oracle文档,此连接池服务将在非活动状态3分钟后关闭连接会话. [ http://docs.oracle.com/html/E10927_01/featConnecting.htm]

  1. 所以最可能的原因是,您的应用程序仍然 通过使用此池连接到数据库,并且仍然连接到 即使您更改了数据库密码也很短时间.
  2. "Oracle客户端缓存"也可能存在一种可能性 ODP.net中的功能.但不太确定,您可以在[ http://www.oracle.com/technetwork/issue-archive/2008/08-jul/o48odpnet-098170.html ]

对于第二个问题:(为什么需要MSDTC)

如果在代码中使用嵌套的数据库连接,它将升级为DTC. [ http://petermeinl.wordpress. com/2011/03/13/avoiding-unwanted-escalation-to-distributed-transactions/]实际上,在ODP.net,DTC和Oracle数据库中,确实有用于Microsoft事务处理服务器(OraMTS)的Oracle服务.

但是在禁用连接池之前,您没有发生此问题(MSDTC).看起来您的代码正在重用未定义的连接池中的同一连接,并且可能消除了升级DTC的需要.关于StaffOverflow也有类似的问题. [为什么我的交易没有升级到DTC?] >

this is really two questions in one I guess.

We've developed a .Net app that accesses an Oracle database, and have noticed that after changing the user's Oracle password, the app continues to work for a short time with the old password in the connection string. Presumably this is something to do with the way existing connections are pooled?

When first investigating this we tried turning off pooling in the connection string, however the app wouldn't work, throwing the error "Unable to enlist in a distributed transaction" at the point it tries to open a connection. While we probably wouldn't want to turn off connection pooling in a production app, I'm curious as to why MSDTC seems to need it?

We are using Oracle 11g (11.1.2) and latest ODP.Net (11.2 I think).

Thanks in advance

Andy

Please see some of the finding below:

For Question One: (application still connected with old DB password)

If we connect the database with connection pooling option, connection pool manager would create and maintain the number of connection sessions when first calling the open or close of OracleConnection object. (number of this connection sessions depend on "min" & "max" pool size in connection string). In Oracle, I think you could check active session like:

SELECT s.inst_id,
       s.sid,
       s.serial#,
       p.spid,
       s.username,
       s.program
FROM   gv$session s
       JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE  s.type != 'BACKGROUND';

And according to Oracle doc, this connection pooling service will close the connection sessions after 3 minutes of in-active state. [ http://docs.oracle.com/html/E10927_01/featConnecting.htm ]

  1. So the most possible reason could be, your application still connected to the database by using this Pool and still connected for a short time, even after you changed the database password.
  2. There could be also one possibility of "Oracle Client Cache" feature in ODP.net. But not quite sure, you can check at, [ http://www.oracle.com/technetwork/issue-archive/2008/08-jul/o48odpnet-098170.html ]

For Question Two: (why MSDTC needed)

If you are using nested Database connection in your code, it will be promoted to DTC. [ http://petermeinl.wordpress.com/2011/03/13/avoiding-unwanted-escalation-to-distributed-transactions/ ] Actually there was Oracle Service for Microsoft Transaction Server (OraMTS) act as among ODP.net, DTC, and Oracle Database.

But you didn't happend this problem (MSDTC) before disabled the connection pooling. It seems like your code is reusing the same connection out of undelining connection pool, and it might eliminate the need to promote DTC. There was similar question on StaffOverflow. [ Why isn't my transaction escalating to DTC? ]