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

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

本文介绍了已有一个与此命令关联的开放DataReader ..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, 我有两个表适配器,我使用.NET 2.0 Web存储在一个缓存中 服务和数据库是SQL Server on Windows 2003 IIS6。 两个表适配器中的每一个都有自己的连接字符串。 表适配器在缓存中的原因是因为我想 维护任何Insert或 更新都不会关闭的连接字符串,因为每分钟有数千个WS请求。 问题是当从表适配器调用Insert或Update时我收到了错误: "已经有一个与此命令关联的打开的DataReader必须首先关闭然后我调用插入或更新 的表适配器从缓存中删除。 感谢先进的任何建议。 AsafHello,I have two Table Adapters that I am storing in a Cache using .NET 2.0 WebService 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 tomaintain the connection string that will not be closed for any Insert orUpdate as there are thousands of requests per minutes to the WS.Problems are that when calling Insert or Update from the table adapters Ireceived the error:"There is already an open DataReader associated with this Command which mustbe closed first" and then the table adapter that I called Insert or Updatefrom is remove from the Cache.Thanks in advanced for any advice.Asaf推荐答案 不需要这样做,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 shouldopen a connection at the last possible moment and close as early aspossible.-- sp**********@rogers.com (Do not e-mail) http:// msdn2。 microsoft.com/en-us/library/8xx3tyca.aspx 好​​吧#1,我自己不会在解决方案中使用表适配器。我会使用带有存储过程的SQL命令对象,这是一个更快的 解决方案,因为它将是一个预编译的存储过程,将保留 内存基于你指明的流量。 至于你试图测试连接池,你应该得到一个 DBA和他或她帮助你。连接池是存在的,它可以工作,这是一个比你目前正在做的更好的解决方案。你应该让 ADO.NET,SQL Server和操作系统为你工作。Well #1, I wouldn''t be using Table Adapters in a solution myself. I wouldbe using SQL Command Objects with a Stored Procedure, which is a fastersolution, because it would be a precompiled Stored Procedure that will stayin memory based on the traffic you indicate.As far as you trying to test the connection pooling, you should get with aDBA 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 letADO.NET, SQL Server and the O/S work for you. 这篇关于已有一个与此命令关联的开放DataReader ..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-03 02:59