0

代码:

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 文件吗?

4

1 回答 1

0

我曾经使用 SQLAnywhere 遇到过这个问题。如果在我的 C# 程序尝试打开数据库的同时打开 SQLAnywhere 管理控制台并连接到数据库,它会给我这个消息。虽然您的数据库引擎不同,但可能是一个类似的问题:在您的 C# 程序尝试打开连接的同时,您打开了一个管理工具,并且一次只允许一个连接。

于 2013-06-11T07:12:05.393 回答