繁体   English   中英

该进程无法访问文件“ * .Yap”,因为它正在被另一个进程C#使用

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

码:

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();
    }
}

例外

    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: 

如何防止这种异常。 我可以先释放.yap文件吗?

我曾经在SQLAnywhere中遇到过这种情况。 如果在我的C#程序试图打开数据库的同时打开SQLAnywhere管理控制台并连接到数据库,它将显示此消息。 尽管数据库引擎不同,但可能是类似的问题:您的C#程序尝试打开连接的同时打开了一个管理工具,一次只允许一个连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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