[英]Database is still locked even after disposing commands
Good day I'm currenlty having a problem on my sqlite database in unity using c#. 美好的一天,我现在统一使用c#在我的sqlite数据库上遇到问题。
So far whenever I tried to read my database it works perfectly fine. 到目前为止,每当我尝试读取数据库时,它都可以正常工作。
But when I try to update it, it always gives me the "Database file is locked" even if there are no commands that are available yet or all commands are disposed and closed. 但是,当我尝试更新它时,即使没有可用的命令或者所有命令都已被处理和关闭,它始终会为我提供“数据库文件已锁定”的信息。
here is my code: 这是我的代码:
string conn = "URI=file:" + Application.dataPath + "/Database/SampleDB";
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection (conn);
dbconn.Open ();
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "UPDATE UserScore SET Highscore = '1'";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
I use this code in both the reading and updating of the database. 我在读取和更新数据库时都使用此代码。 I also tried the "using" command here is the code for reading :
我也尝试过“ using”命令,这里是读取代码:
using (SqliteConnection c = new SqliteConnection(conn))
{
c.Open();
using (SqliteCommand cmd = new SqliteCommand(sqlQuery, c))
{
using (SqliteDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
currHighScore = rdr.GetInt32(0);
currHighDist = rdr.GetInt32(1);
Debug.Log( "High Score : " + currHighScore + ", High Distance: " + currHighDist);
}
}
}
}
and here is for updating: 这里是更新:
using (SqliteConnection c = new SqliteConnection(conn2))
{
c.Open();
using (SqliteCommand cmd = new SqliteCommand(sqlQuery2, c))
{
if (MoveSanji.scoreAccumulate > currHighScore) {
cmd.ExecuteNonQuery(); //or cmd.ExecuteReader();
}
}
}
SOLVED: Apparently I have to restart Unity. 解决:显然我必须重新启动Unity。 I don't know how and why, but it worked.
我不知道如何以及为什么,但是它有效。 :) Thanks for the reponse :)
:)感谢您的回复:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.