我刚开始做样本应用程序,只调用我的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