简体   繁体   English

任何插入查询锁定SQLite

[英]Any Insert Query Locks SQLite

Hello I have a insert query but the problem is it locks the database it is the only connection to the database yet it stays locked does anyone have any idea how to fix it this is the only script i have running and it should work. 您好,我有一个插入查询,但问题是它锁定了数据库,它是与数据库的唯一连接,但仍保持锁定,没有人知道如何解决它,这是我正在运行的唯一脚本,它应该可以工作。

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;  


    }


}

I have tried everything even restarting my computer and trying on another project. 我什至尝试了所有事情,甚至重新启动计算机并尝试另一个项目。

if anyone can please get back to me asap it would be great thank you all for looking 如果有人可以尽快与我联系,那将非常感谢大家的关注

Wrap your connection in a USING statement, so that it will be properly disposed of when you are done: 将连接包装在USING语句中,以便在完成操作后将其正确处置:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM