任何插入查询都会锁定SQLite

本文关键字:锁定 SQLite 插入 查询 任何 | 更新日期: 2023-09-27 17:59:03

你好,我有一个插入查询,但问题是它锁定了数据库——它是与数据库的唯一连接,但它仍然处于锁定状态——有人知道如何修复它吗——这是我运行的唯一脚本,它应该可以工作。

using UnityEngine;
using System.Collections;
using Parse;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Mono.Data.Sqlite; 
using System.Data; 

public class ParseInputId : MonoBehaviour {

    void Start()
    {       
        string conn = "";
        string Question;
        //string sqlQuery;
        #if UNITY_EDITOR
        conn = "URI=file:" + Application.persistentDataPath + "/" + "App.db";
        Debug.Log (conn);
        #elif UNITY_IPHONE
        conn = "URI=file:" + Application.persistentDataPath + "/" + "App.db";
        #elif UNITY_ANDROID
        conn = "URI=file:" + Application.persistentDataPath + "/" + App.db";
        #endif
        //string conn = "URI=file:" + Application.dataPath + "/App.db"; //Path to database.


            string toreplace;
            IDbConnection dbconn;
            dbconn = (IDbConnection) new SqliteConnection(conn);
            dbconn.Open(); //Open connection to the database.
            IEnumerable<ParseObject> results = t.Result;

                IDbCommand dbcmd = dbconn.CreateCommand();


        string sqlQuery = "INSERT INTO TEST (Field1) Values (1)";
                Debug.Log (sqlQuery);
                dbcmd.CommandText = sqlQuery;
                IDataReader reader = dbcmd.ExecuteReader();
                reader.Close();
                reader = null;
                dbcmd.Dispose();
                dbcmd = null;

            dbconn.Close();
            dbconn = null;  

    }

}

我已经尝试了所有的方法,甚至重新启动我的电脑并尝试另一个项目。

如果有人能尽快回复我,那就太好了,谢谢大家寻找

任何插入查询都会锁定SQLite

用USING语句包装您的连接,以便在完成后正确处理:

using (dbconn SqliteConnection =  new (IDbConnection)SqliteConnection(conn))     {
   // Put the rest of your code here.
}