I am running the following function in a service. The function runs fine however the File becomes locked on the server. I get the exception that "the file xyz is being used by another process"
I cannot rename or delete the file on the sever. After about 4 minutes, the file becomes unlocked. If I restart the web Site in IIS the file will immediately unlock.
What is causing the file to become locked at the file level and how can I correct? Is there a Connection string setting I should be using. Am I not closing properly?
Code: Select all
string GetChangeTimeStamp(string FileName)
{
string res = "";
string ConnectString = "datasource="+FileName;
SQLiteConnection SqliteConn = new SQLiteConnection(ConnectString);
SqliteConn.Open();
using (SQLiteCommand cmd = SqliteConn.CreateCommand())
{
cmd.CommandText = "Select value from Settings where parameter = 'ChangedDTime' ";
var r = cmd.ExecuteReader();
if (r.Read())
{
res = r["Value"].ToString().Split('.')[0];
}
else
{
res = "No Date";
}
r.Close();
cmd.Dispose();
}
SqliteConn.Close();
return res;
}