I was recently crashed by a database timeout issue. It took a lot of time and finally solved it. Let's take a look at the highlights and highlights below.
var cx_xscj = from aa in sjklj.xgk_xscj
select aa;
foreach (var kk in cx_xscj)
{
sjklj.xgk_xscj.DeleteObject(kk);
}
sjklj.SaveChanges();
sjklj.Connection.Close (); // No need to close the database to release resources, otherwise it will cause timeout problems
// Create a dataset for offline query and storage
SqlConnection sqlcon = new SqlConnection(conn);
sqlcon.Open();
SqlCommand sqlcmd = new SqlCommand();
sqlcmd.Connection = sqlcon;
sqlcmd.CommandTimeout = 1800; // 30 minutes
sqlcmd.CommandText = "select * from xgk_xscj";
SqlDataAdapter sda_gx_xscj = new SqlDataAdapter (sqlcmd); // For users across the country, also set the where condition to obtain the specified grade and annual data of the specified school, as little as possible.
SqlCommandBuilder scb = new SqlCommandBuilder (sda_gx_xscj); // This is very important, otherwise it may fail to save
DataSet ds_xscj_pm = new DataSet();
sda_gx_xscj.Fill(ds_xscj_pm, "xscj");
sda_gx_xscj.Update (ds_xscj_pm, "xscj"); //.Update(ds, "xscj"); // Last execution
ds_xscj_pm.Dispose();
ds_xscj_tj.Dispose();
sda_gx_xscj.Dispose ();
sqlcon.Close();