在MySQL和C#中请求超时 [英] Request Timeout in Mysql and C#

查看:107
本文介绍了在MySQL和C#中请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我开发了一个Windows应用程序,该应用程序使用基于Internet的MySQL数据库.
我正在连接到服务器并直接执行命令..但是大多数情况下它会超时...这是我的代码的1部分,其中始终显示异常超时...是什么解决方案吗?

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



Thanx

推荐答案

如果建立了连接并且那里没有问题,则从查询中检索数据可能花费了很长时间.我假设这是问题所在,因为失败查询的复杂度比工作查询高得多.您是否有能力在数据库上创建索引?如果不是这样,您可能需要重新考虑您的查询或将超时设置为更高.
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.


这篇关于在MySQL和C#中请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆