在winform中创建一个本地数据库,并在后台从服务器获取数据

时间:2015-09-20 23:57:55

标签: c# mysql database winforms caching

我正在寻找一种方法来增强我的应用程序的性能,该应用程序过度使用托管在服务器上的数据库,应用程序需要远程访问数据库,因此导致它变慢,所以我是考虑创建一个本地数据库并在应用程序运行的那一刻从服务器填充它,然后在每小时后或当用户决定注销时定期更新托管的mySQl数据库,我遇到的主要问题是我将有10-20个用户,他们不会更新相同类型的数据,但我如何知道哪些表已更新,并根据我将更改应用于托管数据库?是否有任何文章或链接有关此问题的进一步解释?

我的应用程序是一个C#windows窗体应用程序,数据库是mysql数据库。

我有一个查询,执行时间太长,这个是:

 /**
  * getting the schedule based on the submitted id
  * */
    public static Schedule2 getTeachersSchedule(String therapistID, int weekday, int period, int school_year)
    {
        // connecting to mysql database
        try
        {
            using (MySqlConnection myConn = new MySqlConnection(connectionString))
            {
                using (MySqlCommand command = new MySqlCommand("Select * FROM student_schedule2, weekday, school_year, period, task where school_year_id = school_year_id_fk AND therapist_id_fk =" + therapistID + " AND weekday_id = weekday_id_fk AND period_id=period_id_fk AND task_id=task_id_fk AND weekday_id=" + weekday + " AND period_id=" + period + " AND school_year_id =" + school_year, myConn))
                {
                    MySqlDataReader reader;
                    myConn.Open();
                    reader = command.ExecuteReader();
                    Schedule2 schedule = null;
                    while (reader.Read())
                    {
                        schedule = new Schedule2();
                        schedule.ID = reader.GetInt32("student_schedule2_id");
                        try
                        {
                            if (reader["student_id_fk"] != DBNull.Value)
                                schedule.student = getStudent(reader.GetString("student_id_fk"));
                            else
                                schedule.student = null;
                            Weekday weekDay = new Weekday();
                            weekDay.ID = reader.GetInt32("weekday_id");
                            weekDay.weekdayName = reader.GetString("weekday_name");
                            schedule.weekday = weekDay;
                            schedule.semesterName = reader.GetString("semester_name");
                            Period periodObj = new Period();
                            SchoolYear schoolYEar = new SchoolYear();
                            periodObj.ID = reader.GetInt32("period_id");
                            periodObj.period_name = reader.GetString("period_name");
                            schedule.period = periodObj;
                            schoolYEar.ID = reader.GetInt32("school_year_id");
                            schoolYEar.year_name = reader.GetString("school_year_name");
                            schedule.schoolYear = schoolYEar;
                            Task course = new Task();
                            course.ID = reader.GetInt32("task_id");
                            course.taskName = reader.GetString("task_name");
                            schedule.task = course;
                            schedule.therapist = getTherapist(reader.GetString("therapist_id_fk"));
                        }
                        catch
                        {

                        }

                    }

                    myConn.Close();
                    return schedule;
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return null;
        }
    }

0 个答案:

没有答案