locked
The asynchronous operation has already completed." RRS feed

  • Question

  • User-1743578003 posted

    Hi am using this code for fetching data from DB -async 

    List<CommunicationPOP> _CommDetails = new List<CommunicationPOP>();
                SqlDataReader _reader;
                IAsyncResult _result;
                using (SqlConnection DBCon = new SqlConnection(ConnectionString.DBConnstring))
                {
                    try
                    {
                        using (SqlCommand DBcmd = new SqlCommand())
                        {
                            DBcmd.Connection = DBCon;
                            DBcmd.CommandTimeout = 0;
                            DBcmd.CommandType = CommandType.StoredProcedure;
                            DBcmd.CommandText = "Usp_GetCommunication";
                            DBcmd.Parameters.AddWithValue("@LeadId", LeadID);
    
                            DBCon.Open();
    
                            _result = DBcmd.BeginExecuteReader(CommandBehavior.CloseConnection);
    
                            while (!_result.IsCompleted)
                            {
                                using (_reader = DBcmd.EndExecuteReader(_result))
                                {
                                    if (_reader.HasRows)
                                    {
                                        while (_reader.Read())
                                        {
                                            _CommDetails.Add(new CommunicationPOP
                                            {
                                                Action = _reader.GetValue(_reader.GetOrdinal("Action")).ToString(),
                                                _dateTime = DateTime.Parse(_reader.GetValue(_reader.GetOrdinal("CreateTime")).ToString()),
                                                CallResult = _reader.GetValue(_reader.GetOrdinal("CallResult")).ToString(),
                                                Details = _reader.GetValue(_reader.GetOrdinal("Details")).ToString(),
                                                Status = _reader.GetValue(_reader.GetOrdinal("Status")).ToString(),
                                                User = _reader.GetValue(_reader.GetOrdinal("User")).ToString(),
                                            });
                                        }
                                    }
                                }
                            }
                        }
    
                        _exc = string.Empty;
                        item = _CommDetails;
    
                    }
    
                    catch (Exception ex)
                    {
                        _exc = ex.Message;
                        DBCon.Close();
                        item = null;
                    }
                    finally
                    {
                        DBCon.Close();
                    }
                }

    Its running fine from my local system - but when deployed on IIs it throwing exception 

    "The asynchronous operation has already completed."

    unable to understand how and where to check .

    Wednesday, May 6, 2015 1:31 PM

All replies

  • User1711366110 posted


    Its running fine from my local system - but when deployed on IIs it throwing exception 
    "The asynchronous operation has already completed."
    unable to understand how and where to check .

      As per my understanding of the given code ,I found the unnecessary comma(,) at the end in this function new CommunicationPOP{} in while loop which makes exception :
    you can try to remove comma from the following area :

    while (_reader.Read())
    {
      _CommDetails.Add(new CommunicationPOP
        {
          Action = _reader.GetValue(_reader.GetOrdinal("Action")).ToString(),
          _dateTime = DateTime.Parse(_reader.GetValue(_reader.GetOrdinal("CreateTime")).ToString()),
          CallResult = _reader.GetValue(_reader.GetOrdinal("CallResult")).ToString(),
          Details = _reader.GetValue(_reader.GetOrdinal("Details")).ToString(),
          Status = _reader.GetValue(_reader.GetOrdinal("Status")).ToString(),
          User = _reader.GetValue(_reader.GetOrdinal("User")).ToString() , //Remove this comma
        });
    }
    

    then rebuild & check it.

    --
    with regards,
    Edwin

    Thursday, May 7, 2015 3:24 AM
  • User-1743578003 posted

    Hi ,

    have removed the same but did not get chance. 

    It is still giving same errror. and as I told is running fine from VS 2010 but when I deply on IIS it throwing said exception.

    Thanks.

    Santosh Jha

    Thursday, May 7, 2015 3:49 AM
  • User1644755831 posted

    Hello Santosh.jha.net,

    I suggested you try an alternative and use sql data adapter rather than reader.

    http://www.dotnetperls.com/sqldataadapter

    "The asynchronous operation has already completed."

    unable to understand how and where to check .

    As the error says it has problem with async method so dataapdater will fill the result in the data table and then you can get the values from it.

    With Regards,

    Krunal Parekh

    Sunday, June 7, 2015 3:19 AM