Tuesday 15 May 2012

c# - The SqlParameter is already contained by another SqlParameterCollection when NOT using a SqlParameterCollection -


I have the following which is throwing an SqlParameter is already an exception in another SqlParameterCollection Code> Hold Block.

What makes me feel weird that we do not make a SqlParameterCollection every time when we create a new example, then SqlParameter is more than one The time is not used and another quirk is that the methodology stored in test has the correct results and returns the results in the calling method, but when I switch from line to line again and again 3 to 4 occurs when it enters the catch block I do not have a 33 in line where I expect ... if it works from any ObjectContext to a DbContext Switching helps using the CodeFirst Generation Tool All other database interactions used and stored actions are working as expected.

  1 attempt 2 {3 tempMessages = Context.CheckExistingTables (importSession.ImportSessionID) .toList (); 4} 5 hold (exception e) 6 {7 this.LogError ("Error validating import file entities", e); 8 tempMessages.Add (New Error Message () {Error Type = 3, Message = string.Format ("Error validating import file entities: {0}", e.Message)}); 9} ... 20 public IEnumerable & lt; Error message & gt; CheckXingTables (Grid? ImportSessionID) 21 {22 SqlParameter Import SessionIDParameter; 23 24 If (importSessionID.HasValue) 25 {26 Import SessionIDParameter = New SqlParameter ("importSessionID", importSessionID); 27} 28 and 29 {30 Import Session ID Parameters = New SQL Pimentator ("ImportCasiaID", Typef (System. Good)); 31} 32 33 var test = Database.SqlQuery & lt; ErrorMessage & gt; ("Import Check Exchanges @ Import SISID", Import SSIDPAMMeter); 34 return examinations; 35}    

Then somehow answer . Was done to call. / Code> 33 at the end of the line.

Note to others ... by using Statement using System.Linq; at the top of your file or you will not have the ToList () option.

No comments:

Post a Comment