简体   繁体   English

包含SQLite.Interop.dll的发布项目失败,因为它正由另一个进程使用

[英]Publishing project that includes SQLite.Interop.dll fails because it is being used by another process

We've recently added SQLite to an existing C# WebForms application running on IIS and we're now having problems publishing it from Visual Studio or Team City . 我们最近将SQLite添加到在IIS运行的现有C# WebForms应用程序,我们现在遇到从Visual StudioTeam City发布它的问题。

If we try to publish after a user has accessed a route that in turn accesses the SQLite DB we get the following error: 如果我们尝试在用户访问路径后发布,而该路由又访问SQLite DBSQLite DB出现以下错误:

Unable to add 'bin/x86/SQLite.Interop.dll' to the Web site. 无法将“bin / x86 / SQLite.Interop.dll”添加到网站。 Unable to add file 'bin\\x86\\SQLite.Interop.dll'. 无法添加文件'bin \\ x86 \\ SQLite.Interop.dll'。 The process cannot access the file because it is being used by another process. 该进程无法访问该文件,因为该文件正由另一个进程使用。

In order to minimize the problem scope I carried out the following steps: 为了最小化问题范围,我执行了以下步骤:

  1. Created a new C# Web API project. 创建了一个新的C# Web API project.
  2. Added the System.Data.SQLite.Core NuGet package. 添加了System.Data.SQLite.Core NuGet package.
  3. Added the code shown below. 添加了下面显示的代码。
  4. Added a publish profile to publish to the local file system and published it. 添加了发布配置文件以发布到本地文件系统并发布它。
  5. Ran the following IISExpress command iisexpress /path:c:\\path-to-application /port:8081 运行以下IISExpress命令iisexpress /path:c:\\path-to-application /port:8081
  6. Navigated to http://localhost:8081/api/values in the browser which correctly responds with the rows from the relevant SQLite table 导航到浏览器中的http://localhost:8081/api/values ,正确响应相关SQLite table的行

If we then try to publish again we receive the error described above, which echoes the problem we see in production under IIS . 如果我们再尝试再次发布,我们会收到上述错误,这与我们在IIS下的生产中看到的问题相呼应。

In order to successfully deploy to the production site we have to stop the app pool , publish and then restart the app pool . 为了成功部署到生产站点,我们必须停止app pool ,发布然后重新启动app pool

This is far from ideal. 这远非理想。 Any thoughts on how we can resolve this issue? 关于我们如何解决这个问题的任何想法?

Here's the code ... 这是代码......

public IEnumerable<string> Get()
{
    var dbPath = HttpContext.Current.Server.MapPath("~/MyDB.sqlite");
    using (var conn = new SQLiteConnection(string.Format("Data Source={0};Version=3;", dbPath)))
    {
        var rows = new List<string>();
        conn.Open();
        var sql = "select * from myTable";
        using (var command = new SQLiteCommand(sql, conn))
        {
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    rows.Add(reader["mycolumn"].ToString());
                }
            }
        }
        return rows;
    }
}

You must stop the web site during deployment. 您必须在部署期间停止该网站。 You should had done that anyway , irrelevant of the DLL locking, because requests handled during the deployment will yield unpredictable results from mixing old and new code. 无论如何 ,你应该这样做,与DLL锁定无关,因为在部署期间处理的请求将产生混合旧代码和新代码的不可预测的结果。

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

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