I'm creating an application which automatically update the database structure is case that database is out of data. Let's call it UpdateApp. That application is invoked by another application which using EntityFramework
to access MySql server. This application is the MainApp. Because it takes a long time to perform the update process, so the main idea is just call update structure when an error (such as no table or no field defined, ...) occurs in the MainApp.
Then, I'd like to make sure my UpdateApp has updated database successfully. Therefore, I want to have the query which causes that error in MainApp before updating and run it again. I try to run debug to find if there is any field in exception objects contains the query, but still cannot find out anything.
try {
using (DbContext ctx = ContextManager.CreateContext()) {
// Do something, for example, get value from database
}
} catch (EntityException ex) {
if (ex.InnerException is MySqlException) {
// 1. Handle update structure, call the UpdateApp here
// 2. Try to get the query and run it again <= I get stuck here
}
}