sql - multiuser log in at same time -
i have created online examination system. working fine single user @ time. however, problem occurs when more 1 user logs in.
there 20 questions in each test. if single user doing test works fine. user can 20 questions. user logs in @ same time. user not getting 20 questions. user1 has completed 12 question. user2 8 question.
suppose there there user1,user2,user3 logged in @ same time. user1 did 8 questions, user2 did 6 questions , user3 8 questions. arrive @ result page without completing 20 questions. means if there 20 users 1 question instead of 20. can help?
try { sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["hasexaminationconnectionstring"].connectionstring); sqlcommand cmd = new sqlcommand(); sqldatareader dr; cmd.connection = con; cmd.commandtext = "select * tblregister name=@name , email=@email"; cmd.parameters.add("@name", sqldbtype.varchar).value = txtstname.text; cmd.parameters.add("@email", sqldbtype.varchar).value = txtstudentid.text; //cmd.parameters.add("@flag", sqldbtype.int).value = convert.toint32(hiddenfield1.value); con.open(); dr = cmd.executereader(); if (dr.read()) { formsauthentication.redirectfromloginpage(txtstname.text, false); session["name"] = txtstname.text; session["email"] = txtstudentid.text; response.redirect("testhome.aspx"); } else { label1.visible = true; label1.text = "username or password required/incorrect."; } } catch { } }
next page:
protected void page_load(object sender, eventargs e) { mob = httpcontext.current.session["name"].tostring(); number = httpcontext.current.session["email"].tostring(); //response.cache.setcacheability(httpcacheability.nocache); if (session["mob"] == null & session["number"] == null) //response.redirect("home.aspx"); if (!ispostback) { dataset testlist = gettestlist("gettestlist"); datalist1.datasource = testlist; datalist1.databind(); } } public dataset gettestlist(string procedurename) { using (dataset questionset = new dataset()) { using (datatable qtable = new datatable()) { qtable.columns.add("testname"); qtable.columns.add("testnumber"); datatable dt; cmd.connection = con; cmd.commandtext = "select * testnumber"; using (da = new sqldataadapter(cmd)) { con.open(); dt = new datatable(); da.fill(dt); if (dt.rows.count > 0) { datarow dr; (int = 0; < dt.rows.count; i++) { dr = qtable.newrow(); dr[0] = dt.rows[i]["testname"].tostring(); dr[1] = dt.rows[i]["testnumber"].tostring(); qtable.rows.add(dr); } } } questionset.tables.add(qtable); return questionset; } } } protected void linkbutton_click(object sender, commandeventargs e) { string name = e.commandargument.tostring(); response.redirect("taketest1.aspx?testno=" + e.commandargument.tostring()); }
next:
protected void page_load(object sender, eventargs e) { //username = session["username"].tostring(); //password = session["password"].tostring(); sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["hasexaminationconnectionstring"].connectionstring); sqlcommand cmd = new sqlcommand(); sqldatareader dr; cmd.connection = con; cmd.commandtext = "select username,password,flag tblcollegeuser username='" + username + "'and password='" + password + "'"; con.open(); dr = cmd.executereader(); if (dr.read()) { hiddenfield1.value = dr["flag"].tostring(); if (hiddenfield1.value.tostring() == "0") { //response.write("<script>alert('your session timer has expired! sorry!')</script>"); response.redirect("result.aspx"); } } if (httpcontext.current.session["name"] == null && httpcontext.current.session["email"] == null) { response.write("<script>alert('your session timer has expired! sorry!')</script>"); response.redirect("default.aspx"); } if (!ispostback) { this.timerstartvalue = long.parse(configurationmanager.appsettings["delay"].tostring()); this.timerinterval = 500; tno = request.querystring["testno"].tostring(); //string query = "select * questions tnumber='" + tno + "'"; questions = getdataset(tno); totalqs = getcount(tno); loadquestion(); dataset questions = new dataset("questions"); questions.tables.add(); } } protected override void onprerender(eventargs e) { base.onprerender(e); string strdisablebackbutton; strdisablebackbutton = ""; clientscript.registerclientscriptblock(this.page.gettype(), "clientscript", strdisablebackbutton); } public dataset getdataset(string query) { using (dataset questionset = new dataset()) { using (datatable qtable = new datatable()) { qtable.columns.add("row_number"); qtable.columns.add("questionno"); qtable.columns.add("tname"); qtable.columns.add("tnumber"); qtable.columns.add("question"); qtable.columns.add("ans1"); qtable.columns.add("ans2"); qtable.columns.add("ans3"); qtable.columns.add("ans4"); datatable dt; using (cmd.connection = con) { //cmd.commandtext = " select * test order checksum(newid()) tnumber='" + query + "'"; cmd.commandtext = " select * test tnumber='" + query + "' order checksum(newid()) "; //cmd.parameters.addwithvalue("@cse", query); da = new sqldataadapter(cmd); con.open(); dt = new datatable(); da.fill(dt); if (dt.rows.count > 0) { datarow dr; (int = 0; < dt.rows.count; i++) { dr = qtable.newrow(); dr[0] = dt.rows[i]["id"].tostring(); dr[1] = "qno" + dt.rows[i]["qno"].tostring(); dr[2] = dt.rows[i]["tname"].tostring(); dr[3] = dt.rows[i]["tnumber"].tostring(); dr[4] = dt.rows[i]["quation"].tostring(); dr[5] = dt.rows[i]["ans1"].tostring(); dr[6] = dt.rows[i]["ans2"].tostring(); dr[7] = dt.rows[i]["ans3"].tostring(); dr[8] = dt.rows[i]["ans4"].tostring(); qtable.rows.add(dr); } } } questionset.tables.add(qtable); return questionset; } } } public int32 getcount(string tno) { return 10; } void page_prerender(object sender, eventargs e) { stringbuilder bldr = new stringbuilder(); bldr.appendformat("var timer = new mytimer({0},{1},'{2}','timerdata');", this.timerstartvalue, this.timerinterval, this.lbltimercount.clientid); bldr.append("timer.go()"); clientscript.registerstartupscript(this.gettype(), "timerscript", bldr.tostring(), true); clientscript.registerhiddenfield("timerdata", timerstartvalue.tostring()); } void page_preinit(object sender, eventargs e) { string timerval = request.form["timerdata"]; if (timerval != null || timerval == "") { timerval = timerval.replace(",", string.empty); timerstartvalue = long.parse(timerval); } } private int32 timerinterval { { object o = viewstate["timerinterval"]; if (o != null) { return int32.parse(o.tostring()); } return 50; } set { viewstate["timerinterval"] = value; } } void redirecttoresults() { response.redirect("results.aspx"); } protected void loadquestion() { if (questions.tables[0].rows.count > 0) { //load question; datarow dr = questions.tables[0].rows[0]; //question.text = dr[0].tostring() + " of " + 20; //question.text = (i + 1).tostring() + " of " + 20; sno = dr[1].tostring(); testname.text = dr[2].tostring(); testno.text = dr[3].tostring(); questionlbl.text = dr[4].tostring(); rbtnans.items.clear(); rbtnans.items.add(dr[5].tostring()); rbtnans.items.add(dr[6].tostring()); rbtnans.items.add(dr[7].tostring()); rbtnans.items.add(dr[8].tostring()); questions.tables[0].rows.remove(dr); if (questionlbl.text.equals(totalqs.tostring())) { islastqs = true; } } else { //end of file; //response.write("<script>alert('thanks presence! can leave now.')</script>"); //session.abandon(); session["raj"] = questions; redirecttoresults(); } } protected void button1_click(object sender, eventargs e) { try { //write code here save question //displays next question sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["hasexaminationconnectionstring"].connectionstring); sqlcommand cmd = new sqlcommand("insert testdisplay values ('" + sno + "','" + session["name"] + "','" + session["email"] + "','" + questionlbl.text + "','" + rbtnans.selecteditem.text + "')", con); con.open(); cmd.executenonquery(); con.close(); loadquestion(); } catch (exception ex) { response.write("<script>alert(''" + ex.message + "'')</script>"); } } protected void button2_click(object sender, eventargs e) { //when skip button pressed loads next question loadquestion(); }
and result page:
protected void page_load(object sender, eventargs e) { l = session["name"].tostring(); m = session["email"].tostring(); sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["hasexaminationconnectionstring"].connectionstring); sqlcommand cmd = new sqlcommand("select tnumber,quation,ans1,ans2,ans3,ans4,ans test left join testdisplay on (test.ans= testdisplay.answ , test.quation= testdisplay.quations) username='" + session["name"] + "' , password='" + session["email"] + "'", con); con.open(); sqldataadapter adp = new sqldataadapter(cmd); adp.fill(dt); con.close(); { int = 20; gridview1.datasource = dt; gridview1.databind(); int marks = gridview1.rows.count; label1.text = convert.toint32(gridview1.rows.count).tostring(); decimal total = convert.todecimal((double)marks / (double)20) * 100; lbltotal.text = total.tostring(); } } public void bind() { // write code summary of result , display } protected void button1_click(object sender, eventargs e) { //response.redirect("home.aspx"); string uniquecode = string.empty; //sqldatareader dr; try { dataset ds = new dataset(); using (sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["hasexaminationconnectionstring"].connectionstring)) { con.open(); sqlcommand cmd = new sqlcommand("select name,email tblregister email= '" + txtemail.text.trim() + "'", con); sqldataadapter da = new sqldataadapter(cmd); da.fill(ds); ////} if (page.isvalid) { //gridview1.rendercontrol(hw); const string server = "relay-hosting.secureserver.net"; mailmessage omail = new mailmessage(); omail.from = new mailaddress("contact@dssgroups.com"); omail.to.add(new mailaddress(txtemail.text.trim())); omail.subject = "your test details"; omail.isbodyhtml = true; // enumeration omail.priority = mailpriority.high; // enumeration omail.body = "hi, <br/><b>please check test details:</b><br/><br/>your marks percentage: " + lbltotal.text+" % "+"<br/>for query contact "+" http://dssgroups.com"; smtpclient sc = new smtpclient(server); sc.enablessl = false; contenttype contenttype = new contenttype(); contenttype.mediatype = mediatypenames.application.octet; contenttype.name = "xml.xml"; sc.send(omail); omail = null; // free resources lblmessage.forecolor = system.drawing.color.darkkhaki; lblmessage.text = "email sent"; scriptmanager.registerstartupscript(this, gettype(), "showalert", "alert('email sent');", true); } else { lblmessage.text = "the email entered not exists."; } } //} } catch (exception ex) { console.writeline("{0} exception caught.", ex); } } protected void button2_click(object sender, eventargs e) { session.clear(); session.abandon(); response.redirect("default.aspx"); }
Comments
Post a Comment