已有一个与此命令关联的开放DataReader .. [英] There is already an open DataReader associated with this Command..

查看:67
本文介绍了已有一个与此命令关联的开放DataReader ..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有两个表适配器,我使用.NET 2.0 Web存储在一个缓存中

服务和数据库是SQL Server on Windows 2003 IIS6。

两个表适配器中的每一个都有自己的连接字符串。


表适配器在缓存中的原因是因为我想

维护任何Insert或

更新都不会关闭的连接字符串,因为每分钟有数千个WS请求。


问题是当从表适配器调用Insert或Update时我收到了错误:

"已经有一个与此命令关联的打开的DataReader必须首先关闭
然后我调用插入或更新

的表适配器从缓存中删除。

感谢先进的任何建议。

Asaf

Hello,

I have two Table Adapters that I am storing in a Cache using .NET 2.0 Web
Service and the Database is SQL Server on Windows 2003 IIS6.
Each of the two table adapters has its own Connection string.

The reason that table adapters are in cache is because I would like to
maintain the connection string that will not be closed for any Insert or
Update as there are thousands of requests per minutes to the WS.

Problems are that when calling Insert or Update from the table adapters I
received the error:
"There is already an open DataReader associated with this Command which must
be closed first" and then the table adapter that I called Insert or Update
from is remove from the Cache.
Thanks in advanced for any advice.
Asaf

推荐答案

=?Utf-8?B?QXNhZg ==?=< AG ** @ newsgroups.nospamwrote in the br />
新闻:B9 ********************************** @ microsof t.com:
=?Utf-8?B?QXNhZg==?= <AG**@newsgroups.nospamwrote in
news:B9**********************************@microsof t.com:

表适配器在缓存中的原因是因为我想

维护不会因任何Insert <而关闭的连接字符串br />
或更新,因为每分钟有数千个请求到WS。
The reason that table adapters are in cache is because I would like to
maintain the connection string that will not be closed for any Insert
or Update as there are thousands of requests per minutes to the WS.



不需要这样做,ADO.NET已经提供了连接池。

维护这样的连接通常是低效的。您应该在最后一刻打开一个连接,并尽早关闭

.


-
sp**********@rogers.com (不要发送电子邮件)

No need to do this, ADO.NET already provides connection pooling.
Maintaining a connection like this is generally inefficient. You should
open a connection at the last possible moment and close as early as
possible.

--
sp**********@rogers.com (Do not e-mail)




" Asaf" < AG ** @ newsgroups.nospamwrote in message

news:B9 **************************** ****** @ microsof t.com ...

"Asaf" <AG**@newsgroups.nospamwrote in message
news:B9**********************************@microsof t.com...

您好,


我有两个表适配器我使用.NET 2.0 Web存储在缓存中

服务,数据库是Windows 2003 IIS6上的SQL Server。

两个表适配器中的每一个都有自己的连接字符串。


表适配器在缓存中的原因是因为我想

维护任何Insert或
更新,因为每分钟有数千个请求到WS.


问题是当从表适配器调用Insert或Update时我是

收到错误:

已经有一个与此命令关联的开放DataReader

必须

先关闭然后我调用插入或更新

的表适配器从缓存中删除。


感谢您提出任何建议。
Hello,

I have two Table Adapters that I am storing in a Cache using .NET 2.0 Web
Service and the Database is SQL Server on Windows 2003 IIS6.
Each of the two table adapters has its own Connection string.

The reason that table adapters are in cache is because I would like to
maintain the connection string that will not be closed for any Insert or
Update as there are thousands of requests per minutes to the WS.

Problems are that when calling Insert or Update from the table adapters I
received the error:
"There is already an open DataReader associated with this Command which
must
be closed first" and then the table adapter that I called Insert or Update
from is remove from the Cache.
Thanks in advanced for any advice.

http:// msdn2。 microsoft.com/en-us/library/8xx3tyca.aspx




" Asaf" < AG ** @ newsgroups.nospamwrote in message

news:93 **************************** ****** @ microsof t.com ...

"Asaf" <AG**@newsgroups.nospamwrote in message
news:93**********************************@microsof t.com...

你好,


我做了一个测试按下时,Web服务向DB插入100条记录

来自IE的调用按钮。


使用此代码时:


TestTableAdapter ta_Test = new TestTableAdapter();

ta_Test.Connection.Open();


for(long i = 0; i< 100 ; i ++)

{

ta_Test.Insert(i);

}


ta_Test。 Connection.Close();


SQL Server 2005 Profiler显示审核登录然后将整个100条记录逐一插入RPC:已完成。然后是审核注销。


当使用这个假设使用连接池的代码时:

TestTableAdapter ta_Test = new TestTableAdapter( );


for(long i = 0; i< 100; i ++)

{

ta_Test.Connection.Open ();

ta_Test.Insert(i);

ta_Test.Connection.Close();

}

SQL Server 2005 Profiler显示审核登录然后插入一条记录

" RPC:Completed"然后是审核注销对于每一行,所以有一个

打开

和插入数据库的每一行的关闭连接。


好​​吗?它需要汇集一个已经打开的连接并且

登录a ??

每个插入行的注销?
Hello,

I did a test with a web service to insert 100 records to DB when pressing
the Invoke button from IE.

When using this code:

TestTableAdapter ta_Test = new TestTableAdapter();
ta_Test.Connection.Open();

for (long i = 0; i < 100; i++)
{
ta_Test.Insert(i);
}

ta_Test.Connection.Close();

SQL Server 2005 Profiler shows "Audit Login" then the whole 100 records to
insert one by one "RPC:Completed" and then the "Audit Logout".
When using this code that suppose to use connection pooling:

TestTableAdapter ta_Test = new TestTableAdapter();

for (long i = 0; i < 100; i++)
{
ta_Test.Connection.Open();
ta_Test.Insert(i);
ta_Test.Connection.Close();
}

SQL Server 2005 Profiler shows "Audit Login" then insert one record
"RPC:Completed" and then the "Audit Logout" for each row, so there is an
Open
and Close connection for each row inserted to the DB.
Doesna??t it needs to pool a connection that is already opened and to
Login a??
Logout for each inserted row?



好​​吧#1,我自己不会在解决方案中使用表适配器。我会使用带有存储过程的SQL命令对象,这是一个更快的

解决方案,因为它将是一个预编译的存储过程,将保留

内存基于你指明的流量。


至于你试图测试连接池,你应该得到一个

DBA和他或她帮助你。连接池是存在的,它可以工作,这是一个比你目前正在做的更好的解决方案
。你应该让

ADO.NET,SQL Server和操作系统为你工作。

Well #1, I wouldn''t be using Table Adapters in a solution myself. I would
be using SQL Command Objects with a Stored Procedure, which is a faster
solution, because it would be a precompiled Stored Procedure that will stay
in memory based on the traffic you indicate.

As far as you trying to test the connection pooling, you should get with a
DBA and have he or she help you. Connection Pooling is there and it works,
which is a better solution, than what you''re doing currently. You should let
ADO.NET, SQL Server and the O/S work for you.


这篇关于已有一个与此命令关联的开放DataReader ..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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