Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello there,

I've developed a windows application which uses internet based MySQL database.
I'm connecting to the server and directly executing commands..But most of the time it's getting timed-out...Here is my 1 part of code in which always showing exception timeout...What's the solution to it???

cmd = connection.CreateCommand();
            string qyery = "select * from employee_details inner join employee_status on employee_details.Employee_Id=employee_status.Emp_Id where employee_status.Emp_Branch_Id=@Emp_Branch_Id and not employee_details.Emp_Type='BM' and not employee_status.Emp_Acc_Stat='DELETED' ";//get the employee account status and emp information simultaneously in the branch of BM
            cmd.Parameters.AddWithValue("@Emp_Branch_Id", home.empBranchId);
            cmd.CommandText = qyery;
            da.SelectCommand = cmd;
            MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
            ds.Clear();
            int m=da.Fill(ds, "Employee_details");


This one is working perfectly.....
dbconnector = new DataConnector();
           conn = new MySqlConnection();
           conn = dbconnector.connect();
           MySqlCommand cmd = new MySqlCommand();
           cmd = conn.CreateCommand();
           string query = "select * from customer_details";
           cmd.CommandText = query;
           try
           {
               da.SelectCommand = cmd;
               MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
               da.Fill(ds, "customer_details");
               MessageBox.Show("filled customer  details  to dataset ");
               DataGridView1.DataSource = ds.Tables["customer_details"];
               conn.Close();
               generatedException = false;
           }
           catch (MySqlException ex)
           {
               MessageBox.Show("Generated Exception=" + ex.ToString());
               generatedException = true;
           }


Thanx
Posted
Updated 10-Mar-11 9:49am
v2

1 solution

If the connection is established and there is no issue there, it could just be taking too long to retrieve the data from the query. I am assuming this is the problem because the complexity of your failing query is much higher than your working query. Do you have the ability to create indexes on the database? If not you may need to rethink your query or set the timeout higher.
 
Share this answer
 
Comments
Dalek Dave 10-Mar-11 16:54pm    
Sage advice
DEB4u 10-Mar-11 17:02pm    
Ya i'm having indexing in tables....Can u help me in how to set the timeout higher? is there any future prob with increasing that?
wizardzz 10-Mar-11 17:08pm    
You can set it in your connection string. CommandTimeout is the parameter
DEB4u 11-Mar-11 3:45am    
What is the difference between command timeout and connection time out?
wizardzz 11-Mar-11 10:08am    
CommandTimeout sets the timeout of your query or stored procedure call. ConnectionTimeout sets the timeout of the attempt to connect, which is this line:
conn = dbconnector.connect();

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