none
Execution stuck at SqlHelper.ExecuteNonQueryAsync function RRS feed

  • Question

  • I am using SQL Helper library to do the update operation in db. library code taken from here https://gist.github.com/imranbaloch/10895917

    I debug the code and saw when this line is executed int recsaffected = await SqlHelper.ExecuteNonQueryAsync(connection, CommandType.Text, SQL);

    Then execution was stuck there and not progressing to the next line.

    I saw data was updated in db, but why were controls not going to next line. Please help me if I've made any mistakes in the code.

    See my code

    public async Task<ResponseContext> UpdateStatus(string downloaddate, string listOfID)
            {
                string SQL = "UPDATE MyTable SET CheckStatus=1 WHERE Convert(varchar,downloaddate,112)=Convert(varchar,'" + downloaddate + "',112) AND ID IN(" + listOfID + ")";
                ResponseContext oContext = new ResponseContext();
    
                try
                {
                    var connection = new SqlConnection(ConnectionManager.GetConnectionString());
                    int recsaffected = await SqlHelper.ExecuteNonQueryAsync(connection, CommandType.Text, SQL);
    
                    if (recsaffected > 0)
                    {
                        oContext.IsSuccess = true;
                        oContext.Message = "Models successfuly updated";
                        oContext.ResponseData = null;
                    }
                    else
                    {
                        oContext.IsSuccess = false;
                        oContext.Message = "No records updated ";
                        oContext.ResponseData = null;
                    }
                }
                catch (Exception ex)
                {
                    oContext.IsSuccess = false;
                    oContext.Message = "Error " + ex.Message.ToString();
                    oContext.ResponseData = null;
                }
    
                return oContext;
            }


    Calling my function this way.

    var task = await _ModelManager.UpdateStatus(Convert.ToString(dtpDate.Value.ToString("yyyy-MM-dd")),listOfID);
    ResponseContext oResponseContext = task as ResponseContext;
    
    public class ResponseContext
    {
        //store true/false as success or fail
        public bool IsSuccess { get; set; }
        //store success or fail message along with exception text
        public string Message { get; set; }
        //we can store anything to response data
        public object ResponseData { get; set; }
    }

    please guide me where i have made the mistake in code for which execution stuck on the line 

    await SqlHelper.ExecuteNonQueryAsync

    thanks

    Monday, October 19, 2020 7:30 PM

All replies

  • Hello,

    I don't believe anyone can assist with this unless they setup a project to use the code as there are 38 instances of ExecuteNonQueryAsync in the source code. The entire page of source code is rather long to sift through.

    Your best option is to debug into what you have already to see what is holding things up.

    int recsaffected = await SqlHelper.ExecuteNonQueryAsync(connection, CommandType.Text, SQL);



    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, October 19, 2020 9:28 PM
    Moderator