2015-06-22 88 views
0

你好,我有一個插入查詢,但問題是它鎖定數據庫它是唯一的連接到數據庫,但它保持鎖定沒有任何人有任何想法如何解決這是我唯一的腳本運行,它應該工作。任何插入查詢鎖SQLite

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; 


    } 


} 

我已經試過一切,甚至重新啓動我的電腦,並試圖在另一個項目。

如果任何人都可以請回到我儘快這將是巨大的感謝大家的期待

+1

如果你沒有收到命令的結果,你應該使用'dbcmd.ExecuteNonQuery()'而不是'dbcmd.ExecuteReader()'。 – Elias

+0

我會試試這個 – albaslayer

+0

這個沒有工作,它仍然不執行查詢 – albaslayer

回答

2

裹在using語句的連接,使之得到妥善處置,當你完成的:

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

我試過了,但它錯過了任何想法,爲什麼它會這樣 – albaslayer

+0

你會得到什麼樣的異常信息? –

+0

ArgumentException:不支持的關鍵字:'uri'。 – albaslayer