Hi
I've written a windows service which reads and writes to sqlite. I've tested some of the code on the server as as a console app- and it works fine, however when I run it as a service it throws the following exception:
Exception: An error occurred while starting a transaction on the provider connection. See the inner exception for details.
Stack: at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.Common.DbConnection.BeginTransaction()
at System.Data.EntityClient.EntityConnection.BeginTransaction()
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
at System.Data.Objects.ObjectContext.SaveChanges()
at DirectoryWatcher.AirQualityFileReader.AddFileToDeletionQueue(String fullPath)
OK, some futher digging into the exception reveals the following error:
Unable to open the database file
However, I can open the same file from a console app.
The Windows Service is run with the Network Services role, and I have given this user/role read/write/modify permissions to the sqlite db.
An example of my code is:
try
{
string err = string.Empty;
if (string.IsNullOrEmpty(ex2.StackTrace))
{
err = "No Error";
}
else
{
err = ex2.StackTrace;
}
using (var context = new SentAttemptsEntities())
{
var id = from i in context.Files
select i.fileId;
Files files = new Files();
files.attempts = newFilePreviousAttempts;
files.errorMessage = err;
files.fileName = fileName;
files.fileId = id.Max() + 1;
context.AddToFiles(files);
context.SaveChanges();
}
}
catch (Exception ex)
{
WriteToEventLog(ex, "Attempted to save attempts to sqlite ", EventLogEntryType.Error);
}
If anyone has any ideas as to why this fails I would greatly appreciate to hear from you.
Thanks