调用并发Web API请求时找不到存储过程

时间:2018-06-27 09:46:47

标签: c# sql asp.net asp.net-web-api stored-procedures

嗨,我有一个get api,它从3个存储过程中请求数据,当它仅调用一次时它可以正常工作,但是当该api同时调用多次时,它会失败,例如当它调用10次,2-3次时失败并发送无法找到存储过程的异常 这是我的功能

  _onOpenGallery = () => {
    if (__DEV__) {console.log("gallery")}
    ImagePicker.openPicker({
      width: 300,
      height: 300,
      cropping: true,
      includeBase64: false,
    }).then(image => {

    }
  )
}

这是我设置连接和填充数据的功能

 public  POSCustomerDetailResponse POSCustomerDetail(string BranchID, string CustomerCode, string AllBranches, string CurrentDate)
        {
            POSCustomerDetailResponse objDetails = new POSCustomerDetailResponse();
            int GramentDue = 0, UnderProcess = 0;
            double AmountDue = 0.0;
            int PendingOrder = 0;
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "sp_CustomerAllStoreData";
            cmd.Parameters.AddWithValue("@Flag", 3);
            cmd.Parameters.AddWithValue("@BranchId", BranchID);
            cmd.Parameters.AddWithValue("@CustCode", CustomerCode);
            cmd.Parameters.AddWithValue("@SelectedBranch", AllBranches);
            cmd.Parameters.AddWithValue("@FilterFlag", 3);
            ds = Appclass.GetData(cmd);
            if (ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dtrow in dt.Rows)
                {
                    GramentDue = GramentDue + Convert.ToInt32(dtrow["ReadyClothes"].ToString());
                    AmountDue = AmountDue + Convert.ToDouble(dtrow["Balance"].ToString());
                    UnderProcess = UnderProcess + Convert.ToInt32(dtrow["BalQty"].ToString());
                }
                PendingOrder = ds.Tables[0].Rows.Count;
            }
            objDetails.PendingOrders = PendingOrder;
            objDetails.DueAmt = Math.Round(AmountDue, 2);
            objDetails.ReadyPcs = GramentDue;
            objDetails.UnderProcessPcs = UnderProcess;

            DataSet ds1 = new DataSet();
            ds1 = GetCustRatings(CurrentDate, BranchID, CustomerCode);
            if (ds1.Tables[0].Rows.Count > 0)
            {
                objDetails.AllRating = Convert.ToInt32(ds1.Tables[0].Rows[0]["AllRating"]);
                objDetails.CurrentRating = Convert.ToInt32(ds1.Tables[0].Rows[0]["CurrentRating"]);
                objDetails.IsActive = ds1.Tables[0].Rows[0]["IsActiveCust"].ToString();
                objDetails.IsNewCustomer = ds1.Tables[0].Rows[0]["NewCustomer"].ToString();
                objDetails.CustomerAtRisk = ds1.Tables[0].Rows[0]["CustomerOverDue"].ToString();
            }

            DataSet ds2 = new DataSet();
            ds2 = GetPackageDetails(CustomerCode, CurrentDate, BranchID);
            if (ds2.Tables[0].Rows.Count > 0)
            {
                objDetails.PackageName = ds2.Tables[0].Rows[0]["PackageName"].ToString();
                objDetails.PackageStartDate = ds2.Tables[0].Rows[0]["StartDate"].ToString();
                objDetails.PackageExpiryDate = ds2.Tables[0].Rows[0]["EndDate"].ToString();
            }
            var dsCust = GetCustomerDetails(BranchID, CustomerCode);
            if (dsCust.Tables[0].Rows.Count > 0)
            {
                objDetails.MemberShipId = dsCust.Tables[0].Rows[0]["MemberShipId"].ToString();
                objDetails.CurrencyType = dsCust.Tables[0].Rows[0]["CurrencyType"].ToString();                
            }

            return objDetails;

        }

0 个答案:

没有答案