解决不了"的SqlParameter已经被其他SqlparameterCollection&QUOT载; [英] Can't solve "Sqlparameter is already contained by another SqlparameterCollection"

查看:1810
本文介绍了解决不了"的SqlParameter已经被其他SqlparameterCollection&QUOT载;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个窗口服务使用2个线程(来自同一个类)。我总是得到同样的错误消息:

I am using 2 threads (from same class) in a windows service. I always getting the same error message:

"The SqlParameter is already contained by another SqlParameterCollection.
   at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index, Object value)
   at System.Data.SqlClient.SqlParameterCollection.Add(Object value)
   at System.Data.SqlClient.SqlParameterCollection.Add(SqlParameter value)
   at DataBaseLayer.SqlDataBaseLayer.FillDataSetFromProcedure(String strStoredProc, ArrayList parameterCollection)
   at TestThread.StartThreads()"

我试图通过创建SqlParameters和一个ArrayList的新实例来解决问题。我也试过在我的清除的ArrayList在代码中循环。这没有解决的问题。我愿意接受任何建议。

I tried to solve the problem by creating new instances of SqlParameters and an Arraylist. I also tried to clear the arraylists at the and of my for loop in the code. This does not solve the problem. I am open to any advice.

推荐答案

您尝试添加一个的SqlParameter SqlParameterCollection 的两倍。这可能会或可能不会在线程间发生的事情。

You are trying to add a SqlParameter to a SqlParameterCollection twice. This may or may not be happening across threads.

如果这是一个多线程问题,那么所有的变量应该在本地范围,因为,如果他们不是你应该在thier访问implemeting sychronisation,可能与锁定

If this is a multi-threading issue then all your variables should be scoped locally because, if they are not you should be implemeting sychronisation on thier access, probably with lock.

如果这不是并发问题的问题应该很容易做一个确定的查找所有引用的SqlParameter 变量。

If this is not a concurrency problem the issue should easily be identified by doing a Find All References on your SqlParameter variable.

无论哪种方式,我们可以更帮助你,如果您发布一些代码。

Either way we can help you more if you post some code.

这篇关于解决不了"的SqlParameter已经被其他SqlparameterCollection&QUOT载;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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