簡體   English   中英

運行程序后,數據庫表被鎖定

[英]DB table getting lock after run the program

我需要將數據插入到TBL_LOAN_DETAILS表。 當調用LoanDetails()方法時,這些數據需要插入表中,在TBL_LOAN_DETAILS ID是自動遞增的。 將數據插入到TBL_LOAN_DETAILS我需要將該記錄ID用作參數, CribProcess()LoanDetails()傳遞另一個稱為CribProcess()方法。 在此之后,經過一些計算/邏輯后,我需要更新TBL_LOAN_DETAILS某些列。 為了實現我使用以下代碼。 (我無法在此處粘貼完整的代碼,因為stackoverflow阻止了它,所以我使用pastebin)。 我在這行lAEntities.TBL_LOAN_DETAILS.Add(tBlLoanDetails);設置了剎車lAEntities.TBL_LOAN_DETAILS.Add(tBlLoanDetails); 程序在此行之后沒有運行。 lAEntities.SaveChanges();

我的部分代碼:請使用鏈接檢查我的完整代碼。

public LoanDetailEntityResponse LoanDetails(string custId, string facilityType, string applyedDate, string currency,string RequiredLoanAmount,string RepaymentPeriod,
                                            string NIC,string CustName,string DateofBirth, string CommunicationAddress,string MobileNumber,string LoanPurpose,string Occupation,string NetIncome,string Expenses,string Education_qualification,
                                            string TypeOfEmployment,string GE_Emp_Category,string Emp_Period,string GE_Position,string PE_Existence, string PE_Position,string SE_Experience,string SE_Business_Nature, string ValueOfAssets,
                                            string SE_Bus_RegNoo_Availability, string SE_Maintain_Financial_Recode, List<LandPropertyAsset> AssetLandList, List<VehicleAsset> AssetVehicleList)
{

    var refNo = string.Empty;
    var response = new LoanDetailEntityResponse();

        var lAEntities = new LAEntities();
        DateTime appDate;
        DateTime DOB;
        using (var transaction = lAEntities.Database.BeginTransaction())
        {
                if (DateTime.TryParse(applyedDate, out appDate))
                 {
                    applyedDate = appDate.ToShortDateString();
                    if (DateTime.TryParse(DateofBirth, out DOB))
                    {
                        DateofBirth = DOB.ToShortDateString();

                         refNo = Common.GetSerialSequence("LOANREFERENCENO", transaction);

                        string approvalStatus = "";
                        int approvalId = 1;
                        decimal loanId = 0;

                        var tBlLoanDetails = new TBL_LOAN_DETAILS
                        {
                            CUSTID = custId,
                            REFNO = refNo,
                            FACILITY_TYPE = facilityType,
                            APPLIED_DATE = applyedDate,
                            CURRENCY = currency,
                            REQLOANAMOUNT = Convert.ToDecimal(RequiredLoanAmount),
                            REPAYMENTPERIOD = RepaymentPeriod,
                            NIC = NIC,
                            CUSTNAME = CustName,
                            DATEOFBIRTH = DateofBirth,
                            COMMUNICATIONADDRESS = CommunicationAddress,
                            MOBILENUMBER = MobileNumber,
                            PURPOSEOFLOAN = LoanPurpose,
                            OCCUPATION = Occupation,
                            NETINCOME = Convert.ToDecimal(NetIncome),
                            EXPENSES = Convert.ToDecimal(Expenses),
                            EDUCATION_QUALIFICATION = Education_qualification,
                            TYPEOFEMPLOYMENT = TypeOfEmployment,
                            GE_EMP_CATEGORY = Convert.ToInt32(GE_Emp_Category),
                            EMP_PERIOD = Convert.ToInt32(Emp_Period),
                            GE_POSITION = Convert.ToInt32(GE_Position),
                            PE_EXISTENCE = Convert.ToInt32(PE_Existence),
                            PE_POSITION = Convert.ToInt32(PE_Position),
                            SE_EXPERIENCE = Convert.ToInt32(SE_Experience),
                            SE_BUS_NATURE = Convert.ToInt32(SE_Business_Nature),
                            SE_BUS_REGNNO_AVAILABILITY = SE_Bus_RegNoo_Availability,
                            SE_MAINTAAIN_FINANTIAL_RECORD = SE_Maintain_Financial_Recode,
                            EMP_VALUEOFASSETS = Convert.ToInt32(ValueOfAssets),
                            LOAN_STATUS_ID = approvalId,
                            REPAYMENTSCORE = 0,
                            PROPOSED_LOAN_FACI_INSTA = 0,
                            EXSISTING_LOAN_FACI_INSTA = 0,
                            ODINTEREST = 0,
                            CREDITCARD = 0,
                            SURPLUS = 0,
                            LOAN_STATUS_DES = "",
                            ISACTIVE = 1,
                            CREATEDBY = "System",
                            CREATEDDATETIME = DateTime.Now,
                            MODIFIEDBY = "System",
                            MODIFIEDDATETIME = DateTime.Now
                        };
                        lAEntities.TBL_LOAN_DETAILS.Add(tBlLoanDetails);
                        lAEntities.SaveChanges();
                        //transaction.Commit();                         

                        var loanDetail = lAEntities.TBL_LOAN_DETAILS.FirstOrDefault(x => x.REFNO.Equals(refNo) && x.ISACTIVE == 1);
                        if (loanDetail != null)
                        {
                            loanId = loanDetail.ID;


                            // Call Crib process
                            AppSettingsReader configReader = new AppSettingsReader();
                            var chromeDriverUrl = (string)configReader.GetValue("ChromeDriverUrl", typeof(string));
                            var navigateUrl = (string)configReader.GetValue("CRIBNavigateUrl", typeof(string));
                            var userName = "";
                            var password = "";
                            CribAutoProcess ca = new CribAutoProcess();
                            int facilityID = int.Parse(loanId.ToString());
                            ca.CribProcess(navigateUrl, userName, password, facilityID, CustName, NIC, "Testing");

                        }
                        }
                }
        }
}

完整代碼在這里

運行程序后, TBL_LOAN_DETAILS表被鎖定,這意味着,當我嘗試使用oracle sql developer刪除表時,此oracle錯誤消息顯示。

ORA-00054:資源正忙並且在指定了NOWAIT的情況下進行獲取,或者超時

由於您正在使用事務,因此您需要執行COMMITROLLBACK 如果不這樣做,則將發生當前所遇到的錯誤,因為該事務仍在使用記錄,而不管您是否使用了using關鍵字並且該記錄都已被處理。

您可以刪除鎖的方法是重新啟動運行oracle的服務,或者殺死持有鎖的oracle中的進程。 之后,oracle將執行其自己的ROLLBACK進程,並且鎖將消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM