c# - 最新的 SQLite 版本错误

标签 c# visual-studio sqlite nhibernate

刚刚通过 Nuget 将我的 SQLite dll 更新到 v1.0.81.0,我收到如下所示的错误。这发生在第一次或多次成功执行之后(不确定)。环境是 x64 机器上的 vs2010,但build设置面向 x86。

我使用 SQLite 对我的 NHibernate 映射进行单元测试。过去经常发现 SQLite 有点“古怪”,我不愿意弄乱工作单元测试夹具(见下文)

有人知道这里出了什么问题吗?

干杯,
贝瑞尔

错误信息

Unable to copy file "...\x86\SQLite.Interop.dll" to "bin\Debug\x86\SQLite.Interop.dll". The process cannot access the file 'bin\Debug\x86\SQLite.Interop.dll' because it is being used by another process. Parties.Data.Impl.NHib.Tests

单元测试夹具(无论如何都足以显示文件访问)

public abstract class SQLiteTestFixture
{

    protected override void BeforeAllTests()
    {
        _configureDbFile();
        base.BeforeAllTests();
    }

    protected override void AfterAllTests()
    {
        base.AfterAllTests();

        _deleteAllDbFiles();
    }

    #region Db File Maintenance

    /// <summary>
    /// Using a file is likely slower than just memory but not noticeably so far,
    /// AND seems to be a bit more stable
    /// </summary>
    private const string DB_FILE_SUFFIX = ".Test.db";

    /// <summary>
    /// Just make some random file name with a known suffix, so we can clean up when done.
    /// </summary>
    private void _configureDbFile()
    {
        _dbFile = Path.GetFullPath(Guid.NewGuid().ToString("N") + DB_FILE_SUFFIX);

        // highly unlikely but just in case the same file is already out there
        _deleteDbFile();
    }

    private void _deleteDbFile()
    {
        if (File.Exists(_dbFile)) File.Delete(_dbFile);
    }

    private static void _deleteAllDbFiles()
    {
        var files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*" + DB_FILE_SUFFIX);
        foreach (var file in files)
        {
            File.Delete(file);
        }
    }

    private string _dbFile;

    #endregion

}

最佳答案

我在使用 SQLite 1.0.88.0 与 VS2010 和 TestDriven.Net 时遇到了这个问题。我尝试了几个 SO 问题的答案,但唯一对我有用的是:

  1. 工具 -> 选项 -> TestDriven.Net -> 常规
  2. Run Test(s) 下,取消选中“在测试运行之间缓存测试过程”
  3. 重新启动 Visual Studio

您现在应该能够运行测试、调试测试、重建等,而无需重新启动进程或 Visual Studio。

关于c# - 最新的 SQLite 版本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12030388/

相关文章:

java - Android - 删除数据库中的行

c# - VTK r(reset)键代码实现

.net - Visual Studio 自动替换引用的程序集

c# - Visual Studio : cannot access resources from code

c# - 转到仅显示公共(public)成员的类定义

c++ - "CREATE TABLE IF NOT EXISTS"语句在 qt sqlite 中不起作用

c++ - 使用 Visual Studio C++ 2013 编译 SQLite 会引发 .c 文件错误

c# - .NET 日志框架

c# - 从数据库中获取浮点值

c# - 为什么我的字典包含两个键相同的条目?