简体   繁体   中英

The process cannot access the file '*.Yap' because it is being used by another process C#

Code:

public Db4oQueueService(Uri baseUri, bool resume)
{
    string fileName = Path.GetFullPath("MyQueue_{0}.Yap".FormatWith(baseUri.GetHashCode()));
    m_Db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), fileName);

    if (!resume)
    {
        ClearQueue();
    }
}

Exception

    Db4objects.Db4o.Ext.DatabaseFileLockedException was unhandled by user code
  Message=SeleniumWinDemo\bin\Debug\MyQueue_177598820.Yap
  Source=Db4objects.Db4o
  StackTrace:
       at Db4objects.Db4o.IO.RandomAccessFileFactory.NewRandomAccessFile(String path, Boolean readOnly, Boolean lockFile)
       at Db4objects.Db4o.IO.FileStorage.FileBin..ctor(BinConfiguration config)
       at Db4objects.Db4o.IO.FileStorage.Open(BinConfiguration config)
       at Db4objects.Db4o.IO.StorageDecorator.Open(BinConfiguration config)
       at Db4objects.Db4o.IO.CachingStorage.Open(BinConfiguration config)
       at Db4objects.Db4o.Internal.IoAdaptedObjectContainer.OpenImpl()
       at Db4objects.Db4o.Internal.ObjectContainerBase._IRunnable_125.Run()
       at Db4objects.Db4o.Foundation.DynamicVariable.With(Object value, IRunnable block)
       at Db4objects.Db4o.Foundation.Environments.RunWith(IEnvironment environment, IRunnable runnable)
       at Db4objects.Db4o.Internal.ObjectContainerBase.WithEnvironment(IRunnable runnable)
       at Db4objects.Db4o.Internal.ObjectContainerBase.Open()
       at Db4objects.Db4o.Internal.IoAdaptedObjectContainer..ctor(IConfiguration config, String fileName)
       at Db4objects.Db4o.Internal.ObjectContainerFactory.OpenObjectContainer(IEmbeddedConfiguration config, String databaseFileName)
       at Db4objects.Db4o.Db4oEmbedded.OpenFile(IEmbeddedConfiguration config, String databaseFileName)
       at Db4oServices.Db4oQueueService..ctor(Uri baseUri, Boolean resume) in D:\PROJEKTI\Db4oServices\Db4oQueueService.cs:line 27
       at Db4oServices.Db4oServicesModule.<Load>b__1(IComponentContext c, IEnumerable`1 p) in D:\Db4oServices\Db4oServicesModule.cs:line 36
       at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p)
       at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
       at Autofac.Core.Resolving.InstanceLookup.Execute()
       at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
       at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
  InnerException: System.IO.IOException
       Message=The process cannot access the file 'SeleniumWinDemo\bin\Debug\MyQueue_177598820.Yap' because it is being used by another process.
       Source=mscorlib
       StackTrace:
            at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
            at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
            at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
            at Sharpen.IO.RandomAccessFile..ctor(String file, Boolean readOnly, Boolean lockFile)
            at Db4objects.Db4o.IO.RandomAccessFileFactory.NewRandomAccessFile(String path, Boolean readOnly, Boolean lockFile)
       InnerException: 

How to prevent this exception. Can I release .yap file before?

I used to run into this with SQLAnywhere. If I had the SQLAnywhere management console open with a connection to the database at the same time my C# program attempted to open the database, it would give me this message. While your database engine is different, it may be a similar issue: you have an administration tool open at the same time your C# program is trying to open a connection, and only one is allowed at a time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM