ADO.NET连接 [英] ADO.NET connections

查看:79
本文介绍了ADO.NET连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们的DBA抱怨来自

aspnet_wp进程的大量连接。


我们在不同的虚拟

目录中部署了多个Web应用程序。我读到了ADO.NET内置连接池的工作原理

是每个app域。所以在我使用单一连接的情况下

string(来自web.config)并且我建议关闭所有连接,建议使用

,假设理想数字是否正确连接
来自aspnet_wp进程的
应该等于我配置的Asp.net web

应用程序的数量?


谢谢为了你的帮助。

解决方案

" Manish Bafna" < Ma ********* @ discussion.microsoft.com写信息

新闻:13 ******************* *************** @ microsof t.com ...


我建议你实现单身模式

连接整个应用程序。


你说你使用的是单连接字符串但是可以



许多连接打开。所以最佳做法是通过实现单例模式打开单个连接




我不能不同意!


在任何情况下都不要这样做!对于连接,单个模式不适用于
。 IMO,你应该只在你真正需要的时候使用单身人士,例如: for.queuing或同步。单身人士可能导致并发/多线程问题以及性能瓶颈,

,特别是在数据库连接方面。


IMO,你应该只在需要的时候实例化一个连接,并在你完成它时立即将其销毁为

。 ADO.net使用连接池来最小化

创建新连接。保持数据库连接的持续时间

尽可能短,以便连接返回到连接

池,下一个数据库事务可以使用它。


根据定义,单身模式使用静态变量 - 比如Highlander,

只能有一个 - 这就是''singleton''的含义,所以

网站的每个用户一直使用相同的连接 - 最好希望你的网站只有一个

的并发用户...此外,还有一个单例模式连接

对象无法扩展到网络园艺或网络耕作

架构。

http://www.velocityreviews.com/forum...plication.html




感谢您的回复。


>

IMO,你应该只在需要的时候实例化一个连接,并在你完成它之后立即将其销毁为

。 ADO.net使用连接池来最小化

创建新连接。保持数据库连接的持续时间

尽可能短,以便连接返回到连接

池,下一个数据库事务可以使用它。



这正是我们在应用程序中所做的。但是现在我们在我们的Oracle

数据库中从aspnet_wp开始经历大量连接。

。虽然我们确定/纠正了可能导致此问题的可能长时间运行的任务/编程错误,但我应该是什么?b $ b在他查询v <时按照预期向DBA说/ BLOCKQUOTE>

会话。那是我很困惑的
。如果我在IIS中运行了四个Web应用程序,使用相同的连接字符串将

连接到Oracle,理想的连接数

在任何时候都应该是4,我是对的吗? ?


Hi,

Our DBA has complained about the large number of connections from the
aspnet_wp process.

We have multiple web applications deployed in different virtual
directories. I read that the way ADO.NET in-built connection pool works
is per app domain. So in a scenario where I am using single connection
string (from web.config) and I am closing all connections as
recommended, is it correct to assume that ideal number of connections
from aspnet_wp process should be equal to the number of Asp.net web
applications that I configured?

Thanks for your help.

解决方案

"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:13**********************************@microsof t.com...

I would suggest you implement singleton pattern for having just single
connection thoughout the application.

You have said that you are using single connnection string but there can
be
many connections open.So best practice is to have single connection open
through out the application by implementing singleton pattern

I couldn''t disagree more!

Under no circumstances do that! A singleton pattern is not appropriate at
all for connections. IMO, you should only use singletons when you really
need to, e.g. for.queuing or synchronisation. Singletons can cause
concurrency/multithreading issues as well as performance bottlenecks,
especially with regards to database connections.

IMO, you should instantiate a connection only when needed, and destroy it as
soon as you''re finished with it. ADO.net uses connection pooling to minimise
the creation of new connections. Keep the duration of database connections
as short as possible so that the connection is returned to the connection
pool where it can be used by the next database transaction.

A singleton pattern, by definition, uses static variables - like Highlander,
there can be only one - that''s what ''singleton'' means, so every user of the
website uses the same connection all the time - best hope you only have one
concurrent user of your site... In addition, a singleton pattern connection
object would not be scalable up to a web gardening or web farming
architecture.

http://www.velocityreviews.com/forum...plication.html



Thanks for the replies.

>
IMO, you should instantiate a connection only when needed, and destroy it as
soon as you''re finished with it. ADO.net uses connection pooling to minimise
the creation of new connections. Keep the duration of database connections
as short as possible so that the connection is returned to the connection
pool where it can be used by the next database transaction.

This is exactly what we are doing in our applications. But now we are
experiencing lot of connection being open from aspnet_wp in our Oracle
database. While we identify/correct the possible long running
tasks/programming mistakes that can cause this issue, what I should be
saying to DBA as expected when he queries for v


sessions. That is
where I am confused. If I have four web apps running in IIS, connecting
to Oracle with same connection string, the ideal number of connections
at any point should be four, am I right??


这篇关于ADO.NET连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆