c# - C# 在发布中的 ASP.NET 中创建 SQLite 数据库导致空数据库
问题描述
我有一个奇怪的问题,在我在网络服务器上创建和填充 SQLite 数据库后,下载后它完全是空的。这是我正在做的事情的片段。
if (!System.IO.File.Exists(sqlitePath))
SQLiteConnection.CreateFile(sqlitePath);
else
{
File.Delete(sqlitePath);
SQLiteConnection.CreateFile(sqlitePath);
}
这是从文本文件加载的 SQL 语句:
CREATE TABLE "tblDriver" (
`Driver_KeyID` INTEGER NOT NULL,
`FirstName` TEXT NOT NULL,
`LastName` TEXT NOT NULL
PRIMARY KEY(`Driver_KeyID`)
)
并通过此方法执行
public void ExecuteSQLiteCommand(List<string> queries, string sqlitePath)
{
using (var conn = new SQLiteConnection(string.Format(@"Data Source={0};Version=3;", sqlitePath)))
{
try
{
conn.Open();
using (SQLiteTransaction transaction = conn.BeginTransaction())
{
foreach (var qry in queries)
{
SQLiteCommand cmd = new SQLiteCommand(qry, conn);
cmd.ExecuteNonQuery();
}
transaction.Commit();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
然后我用
string driverInsertSQL = "INSERT INTO `tblDriver` (`Driver_KeyID`, `FirstName`, `LastName`) VALUES ";
var drivervalues = (from d in drivers.AsEnumerable()
select string.Format("({0}, '{1}', '{2}')",
int.Parse(d["KeyID"].ToString()),
d["FirstName"].ToString(),
d["LastName"].ToString()
)
);
foreach (var item in drivervalues)
{
driverList.Add(string.Format("{0}{1}", driverInsertSQL, item));
}
ExecuteSQLiteCommand(driverList, sqlitePath);
然后我下载文件。当我在 DEBUG 中时,数据库中填充了我所有的数据,但是当我在 RELEASE 中时,甚至没有表。在具有完全相同代码的控制台应用程序中,它以 DEBUG 或 RELEASE 填充数据库。
看起来好像它没有在 RELEASE 中提交数据——即使在我添加了该SQLiteTransaction
片段之后也是如此。
有任何想法吗?
解决方案
我发现了这个问题。
SQLite.Interop.dll
/bin/ 目录中没有更新。即使通过 nuget 更新后,我仍然有旧版本。
推荐阅读
- r - 根据数据框中的 4 个单元格对内容进行分类
- swagger - 修改生成的 Swagger 客户端是不好的做法吗
- oracle11g - 从脚本向 oracle 数据库添加多个函数
- syntax - 在SPSS中创建简单的重复数字序列
- c# - 无法将证书添加到 X509Store
- python - 如何从文件名本身是变量的另一个文件中导入变量
- objective-c - 如何在搜索时突出显示 UILabel 格式的电话号码
- python - 从 URL 下载文件并写入位置
- haskell - postgresql-simple 中的嵌套数据类型
- c# - 在 C# 中使用 getter 和 setter