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:
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;
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..