Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MySQL
i am developing asp.net website with mysql database.
my problem is when i am hitting same page at the same time there is a error in one page that connection must be valid and open.
protected void Page_Load(object sender, EventArgs e)
  {
      try
      {
          if (!IsPostBack)
          {
              Classmysql.getconn();
              txtid.Focus();
              txtname.Text = "neha";
              str = "select max(sno+1) from tblid";
              cmd = new MySqlCommand(str, Classmysql.con);
              dtp = new MySqlDataAdapter(cmd);
              ds = new DataSet();
              dtp.Fill(ds);
              if (ds.Tables[0].Rows[0][0] == DBNull.Value)
              {
                  txtid.Text = "1";
              }
              else
              {
                  txtid.Text = ds.Tables[0].Rows[0][0].ToString();
              }
 
              cmd = new MySqlCommand("insert into tblid values(" + txtid.Text + ",'" + txtname.Text + "','1')", Classmysql.con);
              tn = Classmysql.con.BeginTransaction(IsolationLevel.Serializable);
              cmd.Transaction = tn;
              cmd.ExecuteNonQuery();
              tn.Commit();
 
              str = "select * from tblid";
              cmd = new MySqlCommand(str, Classmysql.con);
              dtp = new MySqlDataAdapter(cmd);
              ds = new DataSet();
              dtp.Fill(ds);
              GridView1.DataSource = ds;
              GridView1.DataBind();
              Classmysql.closeconn();
                     }
      }
      catch (MySqlException ee)
      {
          //  tn.Rollback();
          excepionmethod();
      }
 
  }
classmysql is connection class.
please help.
Posted 14-Feb-13 18:01pm
Comments
Sheikh Muhammad Haris at 15-Feb-13 0:34am
   
Kindly also share the code of your classmysql connection class, so we could understand the connection management process you have done
Member 8825505 at 15-Feb-13 0:37am
   
here is the connetion class code:-
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;
 
///
/// Summary description for Classmysql
///

public class Classmysql
{
//public static string str = ConfigurationManager.ConnectionStrings["pacecrmConnectionString"].ToString();
public Classmysql()
{
//
// TODO: Add constructor logic here
//
}
public static MySqlConnection con;
 
public static void getconn()
{
con = new MySqlConnection();
try
{
string s = ConfigurationManager.ConnectionStrings["pacecrmConnectionString"].ToString();
 
// con.ConnectionString = @"server=localhost;User Id=root; pwd=root;Persist Security Info=True;database=pacecrm ";
con.ConnectionString = s;
con.Open();
}
catch (MySqlException ex)
{
con.Dispose();
con = null;
}
}
public static void closeconn()
{
con.Close();
}
}
Nandakishorerao at 15-Feb-13 1:47am
   
have checked in class file if the getcon() doesnt work then this error occures.if the connection string is not right then connection will not open.verify it again..
Member 8825505 at 15-Feb-13 1:50am
   
that i know if getcon() not work then this error comes but the problem is when the web site is published and accessing same page from different user then this error comes in web page in one of web page which is accessed.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 Peter Leow 205
2 OriginalGriff 200
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100