[英]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 Studio
或Team 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 DB
, SQLite 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: 为了最小化问题范围,我执行了以下步骤:
C# Web API project.
C# Web API project.
System.Data.SQLite.Core NuGet package.
System.Data.SQLite.Core NuGet package.
IISExpress
command iisexpress /path:c:\\path-to-application /port:8081
IISExpress
命令iisexpress /path:c:\\path-to-application /port:8081
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.