I'm using SQL Server 2014 LocalDb with C#. One issue is that if the application is inactive for a certain period of time, the database expires and the next action takes a long time while it re-initializes the database. What is the best way to prevent such timeout?
I'm accessing the database via Linq to Entities.
One approach I tried is calling this function every 60 seconds, but even that doesn't seem to be working properly for some reason.
public async static Task<Version> GetVersionInfoAsync() {
try {
return await Task.Run(() => {
using (Entities context = new Entities()) {
// We must query manually because querying entity objects would fail on outdated databases.
DbVersion Result = context.Database.SqlQuery<DbVersion>("SELECT Major, Minor, Build, Revision FROM Version").FirstOrDefault();
//DbVersion Result = context.DbVersions.Single();
return new Version(Result.Major, Result.Minor, Result.Build, Result.Revision);
}
});
}
catch (Exception ex) {
throw ex;
}
}