ADO.NET,连接池和ASP.NET [英] ADO.NET, connection pooling and ASP.NET

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

问题描述

当两个用户尝试在我们的ASP.NET应用程序中打开相同的记录时,我们偶尔会出现以下错误:


已经有一个与此连接关联的开放DataReader,它必须先关闭



正如建议的那样,我正在关闭连接外部的最后一部分

尝试但我也没有关闭数据阅读器,所以我假设如果发生以下错误,可能会发生上述错误


尝试

打开连接

打开数据阅读器

某些操作导致异常触发

Catch ex As Exception

..处理异常

最后

关闭连接[数据阅读器仍在这里打开]

结束尝试


我已修改此项以关闭数据阅读器以及最后一节

但是会有等到下一个版本,看看是否有这个解析es it。


然而,它提出了一个关于连接池的问题,因此帖子:


是否在ASP.NET中完成连接池会话,申请或其他

级别?当我们查看SQL时,我们会看到来自Web服务器的各种连接

称为.Net SqlClient数据提供程序。我理解

连接池的概念,但在以下情况下会发生什么:


1.用户A打开网页,导致打开连接,数据读取和关闭

连接

2.连接进入池

3.用户B打开相同的网页,导致相同的开放连接,数据读取

和关闭连接


是否(3)重新使用已被放入池中的用户A打开的连接?

是aspnet_wp.exe进程或用户会话的池吗?

谢谢,Rob。

We''re getting an occasional occurrence of the following error when two users
try and open the same record in our ASP.NET app:

"There is already an open DataReader associated with this Connection which
must be closed first."

As suggested, I was closing the connection in the Finally part of the outer
Try but I wasn''t closing the data reader as well so I assume that if the
following happens, the above error could occur

Try
Open connection
Open data reader
Some operation causes the exception to fire
Catch ex As Exception
.. handle exception
Finally
Close the connection [data reader is still open here]
End Try

I''ve modified this to close the data reader as well in the Finally section
but will have to wait until the next release to see if this resolves it.

However, it raised a question about connection pooling, hence the post:

Is connection pooling done in ASP.NET at a session, application or other
level? When we look in SQL, we see various connections from the web server
called ".Net SqlClient data provider". I understand the concept of
connection pooling but what happens in the following situation:

1. User A opens web page causing an open connection, data read and close
connection
2. Connection goes into the pool
3. User B opens same web page causing identical open connection, data read
and close connection

Does (3) re-use the connection opened by User A that''s been put in the pool?
Is the pooling by the aspnet_wp.exe process or against the user''s session?

Thanks, Rob.

推荐答案

您使用的是共享连接对象吗?


如果是这样,这不是您应该在ASP.NET应用程序中执行的操作。

这意味着所有用户都使用相同的连接对象。由于你没有同步访问它,有时多个用户会试图使用它来结束
- 然后你就会收到错误。如果你要同步

访问连接,那只会意味着糟糕的性能,因为用户总是在等待连接对象变得可用。

Rob Nicholson <在****** @ community.nospam>在消息中写道

新闻:uV ************** @ TK2MSFTNGP11.phx.gbl ...
Are you using a Shared connection object?

If so, this is not something you should be doing in an ASP.NET application.
It means that all users are using the same connection object. Since you are
not synchronizing access to it, there are times when multiple users will end
up trying to use it - and then you get an error. If you were to synchronize
access to the connection, it would just mean horrible performance, as users
are always in line waiting for the connection object to become available.
"Rob Nicholson" <in******@community.nospam> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
我们得到了当两个
用户尝试在我们的ASP.NET应用程序中打开相同的记录时偶尔会出现以下错误:

已经有一个打开的DataReader与此相关联必须首先关闭的连接。

正如所建议的那样,我正在关闭
外部的最后部分连接尝试,但我不是''关闭数据阅读器,所以我假设如果发生以下错误,可能会发生上述错误

尝试
打开连接
打开数据阅读器某些操作导致异常触发
Catch ex As Exception
..处理异常
关闭连接[数据读取器仍然在这里打开]
结束尝试

我已经修改了这个以关闭数据阅读器以及最后一节
但是必须等待在下一个版本中看看它是否能解决它。

然而,它提出了一个关于连接池的问题,因此帖子:

连接池是否在ASP.NET中完成会话,应用程序或其他级别?当我们查看SQL时,我们会看到来自Web服务器的各种连接,称为.Net SqlClient数据提供程序。我理解
连接池的概念,但在以下情况下会发生什么:

1.用户A打开网页,导致打开连接,数据读取和关闭
连接
2.连接进入池中
3.用户B打开相同的网页,导致相同的开放连接,数据读取和关闭连接

是否(3)重复使用用户A打开的连接是否已放入
池?
是通过aspnet_wp.exe进程或用户会话进行池化吗?

谢谢,Rob。
We''re getting an occasional occurrence of the following error when two
users
try and open the same record in our ASP.NET app:

"There is already an open DataReader associated with this Connection which
must be closed first."

As suggested, I was closing the connection in the Finally part of the
outer
Try but I wasn''t closing the data reader as well so I assume that if the
following happens, the above error could occur

Try
Open connection
Open data reader
Some operation causes the exception to fire
Catch ex As Exception
.. handle exception
Finally
Close the connection [data reader is still open here]
End Try

I''ve modified this to close the data reader as well in the Finally section
but will have to wait until the next release to see if this resolves it.

However, it raised a question about connection pooling, hence the post:

Is connection pooling done in ASP.NET at a session, application or other
level? When we look in SQL, we see various connections from the web server
called ".Net SqlClient data provider". I understand the concept of
connection pooling but what happens in the following situation:

1. User A opens web page causing an open connection, data read and close
connection
2. Connection goes into the pool
3. User B opens same web page causing identical open connection, data read
and close connection

Does (3) re-use the connection opened by User A that''s been put in the
pool?
Is the pooling by the aspnet_wp.exe process or against the user''s session?

Thanks, Rob.



Elo,


连接池无法返回相同的连接对象很多客户。我想b / b $ b你认为你要离开读者了。填写数据后你必须关闭阅读器/连接




-

Milosz Skalecki

MCP,MCAD

" Rob Nicholson"写道:
Elo,

Connection pool cannot return the same connection object to many clients. I
think you are leaving reader opened. You have to close reader/connection
after populating the data.

--
Milosz Skalecki
MCP, MCAD
"Rob Nicholson" wrote:
当两个用户尝试在我们的ASP.NET应用程序中打开相同的记录时,我们偶尔会出现以下错误:

已经有一个打开的DataReader与此Connection相关联,必须先关闭它。

正如所建议的那样,我正在关闭最后部分的连接。外部尝试但是我也没有关闭数据阅读器,所以我假设如果发生以下错误,可能会发生上述错误

尝试打开
连接
打开数据阅读器
某些操作导致异常触发
Catch ex As Exception
..处理异常
关闭连接[数据读取器]仍然在这里开放]
结束尝试

我已经修改了这个以关闭数据阅读器以及最后一节
但是必须等到下一个版本到看看这是否能解决它。

然而,它提出了一个关于连接池的问题,因此帖子:

连接池是在ASP.NET中的会话,应用程序还是其他级别完成的?当我们查看SQL时,我们会看到来自Web服务器的各种连接,称为.Net SqlClient数据提供程序。我理解
连接池的概念,但在以下情况下会发生什么:

1.用户A打开网页,导致打开连接,数据读取和关闭
连接
2.连接进入池中
3.用户B打开相同的网页,导致相同的开放连接,数据读取和关闭连接

是否(3)重复使用用户A打开的连接是否已放入池中?
是否通过aspnet_wp.exe进程或用户的会话进行池化?

谢谢,Rob。
We''re getting an occasional occurrence of the following error when two users
try and open the same record in our ASP.NET app:

"There is already an open DataReader associated with this Connection which
must be closed first."

As suggested, I was closing the connection in the Finally part of the outer
Try but I wasn''t closing the data reader as well so I assume that if the
following happens, the above error could occur

Try
Open connection
Open data reader
Some operation causes the exception to fire
Catch ex As Exception
.. handle exception
Finally
Close the connection [data reader is still open here]
End Try

I''ve modified this to close the data reader as well in the Finally section
but will have to wait until the next release to see if this resolves it.

However, it raised a question about connection pooling, hence the post:

Is connection pooling done in ASP.NET at a session, application or other
level? When we look in SQL, we see various connections from the web server
called ".Net SqlClient data provider". I understand the concept of
connection pooling but what happens in the following situation:

1. User A opens web page causing an open connection, data read and close
connection
2. Connection goes into the pool
3. User B opens same web page causing identical open connection, data read
and close connection

Does (3) re-use the connection opened by User A that''s been put in the pool?
Is the pooling by the aspnet_wp.exe process or against the user''s session?

Thanks, Rob.



连接池在AppDomain级别完成。对于asp.net,这意味着

应用程序(同一个vdir的所有asp.net线程)。


连接由连接字符串汇集(即存在是每个

连接字符串的池。当请求连接时,如果在

池中找到一个连接,则重用它,如果没有创建连接。当一个连接关闭时,它返回到池中。计时器启动,如果未重复使用

在指定的时间限制内实际关闭。


连接返回池时发生错误(连接

已关闭),但是datareader没有读取所有结果集(这种情况发生了

,读取器已关闭),因此连接仍在使用中(到

sqlserver)。真正的issuse是

连接上有未决结果集,在通过连接向

sqlserver发送新请求之前不会检测到。 asp.net本来可以先发送取消请求

,但这需要额外的网络往返。


- bruce(sqlwork.com)

" Rob Nicholson" <在****** @ community.nospam>在消息中写道

新闻:uV ************** @ TK2MSFTNGP11.phx.gbl ...
connection pooling is done at the AppDomain level. for asp.net this means at
the application (all asp.net threads for the same vdir).

connections are pooled by connection string (ie there is a pool per
connection string). when a connection is requested, if one is found in the
pool its reused, if not a connection is created. when a connection is
closed, its returned to the pool. a timer is started, and if its not reused
in the specified time limit is actually closed.

the error happens when a connection is returned to the pool (the connection
is closed), but a datareader has not read all results sets (this happens
with the reader is closed), so the connection is still in use (to
sqlserver). the real issuse is there is pending results sets on the
connection, that will not be detected until a new request is sent to
sqlserver over the connection. asp.net could have sent a cancel request
first, but this would require an extra network round trip.

-- bruce (sqlwork.com)
"Rob Nicholson" <in******@community.nospam> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
我们得到了当两个
用户尝试在我们的ASP.NET应用程序中打开相同的记录时偶尔会出现以下错误:

已经有一个打开的DataReader与此相关联必须首先关闭的连接。

正如所建议的那样,我正在关闭
外部的最后部分连接尝试,但我不是''关闭数据阅读器,所以我假设如果发生以下错误,可能会发生上述错误

尝试
打开连接
打开数据阅读器某些操作导致异常触发
Catch ex As Exception
..处理异常
关闭连接[数据读取器仍然在这里打开]
结束尝试

我已经修改了这个以关闭数据阅读器以及最后一节
但是必须等待在下一个版本中看看它是否能解决它。

然而,它提出了一个关于连接池的问题,因此帖子:

连接池是否在ASP.NET中完成会话,应用程序或其他级别?当我们查看SQL时,我们会看到来自Web服务器的各种连接,称为.Net SqlClient数据提供程序。我理解
连接池的概念,但在以下情况下会发生什么:

1.用户A打开网页,导致打开连接,数据读取和关闭
连接
2.连接进入池中
3.用户B打开相同的网页,导致相同的开放连接,数据读取和关闭连接

是否(3)重复使用用户A打开的连接是否已放入
池?
是通过aspnet_wp.exe进程或用户会话进行池化吗?

谢谢,Rob。
We''re getting an occasional occurrence of the following error when two
users
try and open the same record in our ASP.NET app:

"There is already an open DataReader associated with this Connection which
must be closed first."

As suggested, I was closing the connection in the Finally part of the
outer
Try but I wasn''t closing the data reader as well so I assume that if the
following happens, the above error could occur

Try
Open connection
Open data reader
Some operation causes the exception to fire
Catch ex As Exception
.. handle exception
Finally
Close the connection [data reader is still open here]
End Try

I''ve modified this to close the data reader as well in the Finally section
but will have to wait until the next release to see if this resolves it.

However, it raised a question about connection pooling, hence the post:

Is connection pooling done in ASP.NET at a session, application or other
level? When we look in SQL, we see various connections from the web server
called ".Net SqlClient data provider". I understand the concept of
connection pooling but what happens in the following situation:

1. User A opens web page causing an open connection, data read and close
connection
2. Connection goes into the pool
3. User B opens same web page causing identical open connection, data read
and close connection

Does (3) re-use the connection opened by User A that''s been put in the
pool?
Is the pooling by the aspnet_wp.exe process or against the user''s session?

Thanks, Rob.



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

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