.net - CLR: System.InvalidOperationException: The context connection is already in use -


I get this error when I try to make a display in the middle of my datestor:

System .United exception: Connection connection is already in use.

Let me repeat all the rows that should be repeated through the data reader because many lines have been returned.

> SqlConnection conn = New SqlConnection ("Reference Connection = True");

  SqlCommand CMD = new SqlCommand (); Cmd.Connection = conn; Cmd.CommandType = CommandType.StoredProcedure; Cmd.CommandText = "spClean_Select_Product_For_Delete"; CMD. Comma timeout = 41600; Conn.Open (); SqlDataReader Reader = cmd.ExecuteReader (); Try {SqlContext.Pipe.Send (DateTime.Now.ToString () + "- started working with the product"); While (reader.Read ()) {SqlContext.Pipe.ExecuteAndSend (New SqlCommand ("Product Product from Einfo Productivity =" + Reader ["Product Id"]. ToString ()); } SqlContext.Pipe.Send (DateTime.Now.ToString () + "- Complete the work with the product"); } Finally {conn.Close (); // Always close the call when reading reader.Close (); }   

The most likely reason for this exception is that you send the command to be removed We are selecting the record to delete the server at the same time. I suggest that you first collect all the product IDs you want to delete and only delete:

  Ichling & lt; Int & gt; ProductIds = NewHashet & lt; Int & gt; (); (Var cmer = new SqlCommand ("spClean_Select_Product_For_Delete")) (var reader = cmd.ExecuteReader ()) {var productId = (int) reader ["ProductId"]; ProductIds.Add (productId); }} String deleteCmdString = "Delete the product from the product that has been produced (" + productIdsString + ")"; SqlContext.Pipe.ExecuteAndSend (New SqlCommand (deleteCmdString))  

The above code is probably not full or correct, but you should get this idea.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -