我剛開始做樣本應用程序,只調用我的sqlite數據庫上的一些表,我已經設法解決除了這個以外發生的其他問題!儘管我搜索了連接字符串和權限問題的建議解決方案,並且對於我的許可似乎都不合法,因此我向所有用戶添加了完全控制權並且仍然存在相同錯誤。下面是我的代碼我試圖執行:SQLIte無法打開數據庫
// calling function
void getrecords2()
{
MySqlLite.DataClass ss = new MySqlLite.DataClass();
DataTable dt = ss.selectQuery("select * from english_words");
}
//the SQLite class that execute the code
using System.Data;
using System.Data.SQLite;
namespace MySqlLite
{
class DataClass
{
private SQLiteConnection sqlite;
public DataClass()
{
//This part killed me in the beginning. I was specifying "DataSource"
//instead of "Data Source"
sqlite = new SQLiteConnection(@"Data Source=C:\testwork\db\MrPick.sqlite3.db;Version=3;FailIfMissing=True");
}
public DataTable selectQuery(string query)
{
SQLiteDataAdapter ad;
DataTable dt = new DataTable();
try
{
SQLiteCommand cmd;
sqlite.Open(); //Initiate connection to the db
cmd = sqlite.CreateCommand();
cmd.CommandText = query; //set the passed query
ad = new SQLiteDataAdapter(cmd);
ad.Fill(dt); //fill the datasource
cmd.Dispose();
sqlite.Dispose();
}
catch (SQLiteException ex)
{
//Add your exception code here.
}
sqlite.Close();
return dt;
}
}
}
注:我用下面的assemply: SQLite的ADO.NET數據提供 版本1.0.82.0 2012年9月3日 使用SQLite 3.7.14 最初寫作者:Robert Simpson 發佈到公共領域,使用須自負風險! 官方供應商網站:http://system.data.sqlite.org/
我真的很感謝你對此的幫助。
好的,有什麼例外,你在哪裏得到它? – cdhowie
你確定,是你的db 3的版本嗎? –
異常是:System.Data.SQLite.SQLiteException(0x80004005):無法打開數據庫文件 – Rama