Click here to Skip to main content
15,884,877 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.
C#
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
Comments
[no name] 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 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();
}
}
Nandakishore G N 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 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)



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