mercredi 27 mai 2015

Sqlite entity framework unable to open file on update

I am completely baffled by this error. I used to get the unable to open file error when I was reading from the database file. I figured out I had a file path issue and fixed it. Now I get it when I try and update the database. This happens after a read. Why would it fail to open on an update but not a read?

using (var con = new UploadContext())
{
    upload = con.Uploads.SingleOrDefault(u => u.HashId == hashId);

    if (upload == null)
    {
        upload = new Upload()
        {
            HashId = hashId,
            StartTime = DateTime.UtcNow,
            UploadId = generate()
        };

        con.Uploads.Add(upload);
        con.SaveChanges();
    }
}
...

error looks like this:

System.Data.Entity.Infrastructure.DbUpdateException was unhandled by user code
  HResult=-2146233087
  Message=An error occurred while updating the entries. See the inner exception for details.
  Source=EntityFramework
  StackTrace:
       at System.Data.Entity.Internal.InternalContext.SaveChanges()
       at FileServer.Services.UploadService.GetUpload(String fileName, Int32 size, Int32 userId) in ...\\UploadService.cs:line 67
       at FileServer.Controllers.FilesController.PreUpload(PreUploadInfoModel model) in ...\FilesController.cs:line 31
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
  InnerException: System.Data.Entity.Core.UpdateException
       HResult=-2146233087
       Message=An error occurred while updating the entries. See the inner exception for details.
       Source=EntityFramework
       StackTrace:
            at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
            at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
            at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
            at System.Data.Entity.Internal.InternalContext.SaveChanges()
       InnerException: System.Data.SQLite.SQLiteException
            HResult=-2147467259
            Message=unable to open database file
unable to open database file
            Source=System.Data.SQLite
            ErrorCode=14
            StackTrace:
                 at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
                 at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
                 at System.Data.SQLite.SQLiteDataReader.NextResult()
                 at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
                 at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
                 at System.Data.SQLite.SQLiteCommand.ExecuteDbDataReader(CommandBehavior behavior)
                 at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
                 at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
                 at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
                 at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
            InnerException: 

Aucun commentaire:

Enregistrer un commentaire