Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a asp.net page which is published online.This page inserts a records a table.The problem arises when this page is accessed from two different locations at the same time for saving data.Well, I am using a transaction too.

The Code Snippet is given below:
C#
mConn = new OdbcConnection();
       mConn.ConnectionString = Global.mconnectionstr;
       mConn.Open();
       mTrans = mConn.BeginTransaction(IsolationLevel.Serializable);
       string mkey = "000000" + lib.FnGenAutoCode("MR", "RECURR", "PAY", 6, mTrans, (string)Session["COMPANYID"].ToString(), Session["BRANCHID"].ToString());
       MONEY_RECEIPT = "MR/" + mkey.Substring(Convert.ToInt16(mkey.Length - 6), (Convert.ToInt16(mkey.Length) - Convert.ToInt16(mkey.Length - 6)));
       if (ReadGrid())
       {
           int key = lib.FnGenAutoCode("TRN_COMMISSION_PAID", "TRN_COMMISSION_PAID", "TRN_COMMISSION_PAID", 5, mTrans, (string)Session["COMPANYID"].ToString(), Session["BRANCHID"].ToString());
           string fStrSql = " INSERT INTO [TRN_COMMISSION_PAID] VALUES (" +
          " '" + (string)Session["COMPANYID"].ToString() + "','" + Session["BRANCHID"].ToString() + "','" + key + "','" + adv_code + "','" + txtTotal.Text + "','" + DateTime.Now.Date.ToString("MM/dd/yyyy") + "'" +
          ",'" + MONEY_RECEIPT + "','" + tds_amt.ToString() + "','" + serv_amt.ToString() + "','" + project_amt.ToString() + "'" +
          " ,'" + payable_amt + "','" + Session["User"].ToString() + "','" + DateTime.Now.Date.ToString("MM/dd/yyyy") + "','','','I','" + txtLoan.Text + "')";
           if (lib.FnExecuteQuery(fStrSql, mTrans) && UpdateLoanAmount())
           {
               UserMsg = "Data saved successfully";
               lblstatus.Text = UserMsg;
               //PendingInstallMent(txtAdvisor.Text);
               clerfld();
               mTrans.Commit();
               string sql_adv = "select CODE from TRN_ADVISOR where REFCODE='" + txtAdvisor.Text + "'";
               string adv = lib.FnFetchText(sql_adv);

               Response.Write("<script>");
               Response.Write("window.open('CommissionVoucher.aspx?moneyreceipt=" + MONEY_RECEIPT +
                   "&adv=" + adv +
                   "&frmdate=" + lib.FnQuatationRps(txtFrmDate.Text) +
                   "&todate=" + lib.FnQuatationRps(txtToDate.Text) + "','_blank')");
               Response.Write("</script>");
           }
           else
           {
               lblstatus.Text = "Unable to Save record";
               mTrans.Rollback();
           }
           mTrans.Dispose();
           mConn.Close();
       }
       mTrans.Dispose();
       mConn.Close();


Please Help..
Posted

Hi,
Read Following Doc Carefully You Will get All Things........

[ http://www.developerfusion.com/article/84418/concurrency-handling-techniques-in-adonet/]
 
Share this answer
 
v2
There are several things you can do to improve the concurrency issue.
1. IsolationLevel Serializable: to avoid unless it is important to ensure the highest level of data integrity.
In your case you are inserting data (you are not potentially updating the same record) and you do not need Serializable (i would use ReadCommitted).
2. Reduce your transaction to the bare minimum (ie: if you need to calculate the string that contains the query then do it before you start the transaction). Limiting in time an open transaction can help with high volume apps.
3. Have a good maintenance plan. Sometimes fragmented indexes can have an impact on concurrences issues (avoid the use of "SELECT * From Table")

This is just the beginning, every application and database has his own set of rules for managing a better concurrences.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900