jmohan
07-25-2008, 12:33 PM
Hi all,
I need to execute two functions(idfn, urlfn) simultaneously. Therefore, I am using the thread concept in the asp.net with c#. Back end is mysql 5.1 database.
When the thread concept is used with database connection, the two threads are not executed properly. I use the following codings,
Thread firstthread;
Thread secondthread;
protected void Page_Load(object sender, EventArgs e)
{
string str = ConfigurationManager.AppSettings["mysql"];
con = new OdbcConnection(str);
ThreadStart t1 = new ThreadStart(idfn);
ThreadStart t2 = new ThreadStart(urlfn);
firstthread = new Thread(t1);
secondthread = new Thread(t2);
firstthread.Start();
secondthread.Start();
}
void idfn()
{
con.Open();
cmd = new OdbcCommand("select userid from user_id", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(dr.GetString(0));
}
dr.Close();
con.close();
}
void urlfn()
{
con.Open();
cmd = new OdbcCommand("select userurl from user_url_summary", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList2.Items.Add(dr.GetString(0));
}
dr.Close();
con.close();
}
But the connection with the database is not established properly, Data are not loaded into two drop down list. please guide me.
J. Mohan.
I need to execute two functions(idfn, urlfn) simultaneously. Therefore, I am using the thread concept in the asp.net with c#. Back end is mysql 5.1 database.
When the thread concept is used with database connection, the two threads are not executed properly. I use the following codings,
Thread firstthread;
Thread secondthread;
protected void Page_Load(object sender, EventArgs e)
{
string str = ConfigurationManager.AppSettings["mysql"];
con = new OdbcConnection(str);
ThreadStart t1 = new ThreadStart(idfn);
ThreadStart t2 = new ThreadStart(urlfn);
firstthread = new Thread(t1);
secondthread = new Thread(t2);
firstthread.Start();
secondthread.Start();
}
void idfn()
{
con.Open();
cmd = new OdbcCommand("select userid from user_id", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(dr.GetString(0));
}
dr.Close();
con.close();
}
void urlfn()
{
con.Open();
cmd = new OdbcCommand("select userurl from user_url_summary", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList2.Items.Add(dr.GetString(0));
}
dr.Close();
con.close();
}
But the connection with the database is not established properly, Data are not loaded into two drop down list. please guide me.
J. Mohan.