in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

error when running as a windows service

Last post 09-08-2010 9:16 AM by Magick93. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-31-2010 7:20 AM

    error when running as a windows service

    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

  • 09-08-2010 9:00 AM In reply to

    Re: error when running as a windows service

    Whats your connection string?
  • 09-08-2010 9:16 AM In reply to

    Re: error when running as a windows service

    I figured it out. It was a folder permission issue. Network Services needed write permissions on the folder, and not just the sqlite db, due to the creation of the journal file.
Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems