2011-11-25 95 views
-2

我的項目有一個對SQLite.Interop.066.dll的引用,甚至在將SQLite數據庫放入正確的路徑後,應用程序仍然無法找到它。 A返回SQLiteException was unhandled錯誤:無法打開數據庫文件,SQLiteException未處理

 SQLiteConnection conn = new SQLiteConnection(); 
     //SQLiteDataAdapter da; 
     SQLiteCommandBuilder cb; 
     DataTable dt=new DataTable(); 
     int row = 0; 

     conn.ConnectionString = "Data Source=C:\\database\\info.db; Version=3"; 
     conn.Open(); 

     DataRow dr = dt.NewRow(); 
     dr["name"] = txtName.Text; 
     dr["address"] = txtAddress.Text; 
     dr["phone"] = txtPhone.Text; 
     dr["position"] = txtPosition.Text; 
     dt.Rows.Add(dr); 
     da.Update(dt); 

     row = dt.Rows.Count - 1; 
     txtName.Text = dt.Rows[row]["name"].ToString(); 
     txtAddress.Text = dt.Rows[row]["address"].ToString(); 
     txtPhone.Text = dt.Rows[row]["phone"].ToString(); 
     txtPosition.Text = dt.Rows[row]["position"].ToString(); 

     da.Fill(dt); 

     cb = new SQLiteCommandBuilder(da); 

     conn.Dispose(); 
     conn.Close(); 

在行上發生異常:conn.Open();
對不起之前的錯誤標題錯誤...

+3

你有什麼試過的?這個錯誤出現在什麼情況/上下文中? –

+1

請顯示一些代碼... –

+0

對不起,沒有更多的細節幫助。 – CouncilScribe

回答

1

看看適合的格式,可以在這裏找到一個SQLite連接字符串:http://www.connectionstrings.com/sqlite

初看起來,您似乎錯過了「info」上的文件擴展名以及可能適用於您的實現的任何必需的連接字符串選項(同樣請參閱connectionstrings.com以獲取幫助)。

由於錯誤是由conn.Open()引發的「索引超出範圍」異常,它聽起來好像只是無法找到數據庫,修復擴展可能只是伎倆。

+0

雖然我將數據庫名稱重命名爲info.db,但得到同樣的錯誤... – rose

+0

我不是SQLite專家,但是通過查看'connectionStrings.com'上的示例並執行一些Google搜索,看起來您需要包含連接字符串的'Version'子句。另外,請確保您的數據庫版本爲3或更高,因爲它看起來版本2不適用於您正在使用的System.Data.SQLite.SQLiteConnection對象。 –

+0

我敢肯定我的sqlite ado.net數據庫是以上版本3 – rose

0
conn.ConnectionString = "Data Source=C:\\database\\info.db; Version=3;"; 
相關問題