简体   繁体   English

即使处置命令后,数据库仍处于锁定状态

[英]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.

相关问题 即使处置数据库连接后,SQLitePCL.SQLiteResult也会在Step()上返回“ BUSY” - SQLitePCL.SQLiteResult returning “BUSY” on Step() even after Disposing the Database Connection 即使丢弃,ShowDialog中的内存泄漏 - Memory leak in ShowDialog even after disposing it 即使配置了计时器,计时器回调仍在执行 - timer callback is executing even after disposing the timer 写入后 StorageFile 仍然锁定 - StorageFile still locked after writing 即使使用多线程,UI仍然会被锁定 - UI still locked up even with multi threading 部署异步套接字(.Net)后,仍会调用回调 - After disposing async socket (.Net) callbacks still get called SQLite数据库在更新后被锁定为C#? - SQLite database is locked C# after update? 即使在连接字符串中指定了登录凭据后,用户仍然收到错误消息,表明其用户无法访问数据库 - Even after i specify login credentials in a connection string, users are still getting an error that their user cannot access a database 表单关闭后未处置 - Form is not disposing after closing it ObjectDisposedException 即使在将客户端处理程序设置为 false 之后,我也不会处理和使用同一个实例 - ObjectDisposedException even after setting client handler to false so I'm not disposing and using the same instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM