我编写了一个小型 C#/.Net 应用程序,它能够读取 Firefox 的 cookies.sqlite 文件。由于我升级到 Firefox 4,我的应用程序无法打开数据库文件:
执行“connection.Open();”行 (在下面的代码示例中)将有一个 execption 说:
“打开的文件不是数据库文件。文件已加密或不是数据库”
这是我的程序代码:
class Program
{
static void Main()
{
const string PATH_TO_DATABASE = @"C:\Users\Boris\Desktop\TEMP\cookies.sqlite";
const string CONNECTION_STRING = @"Data Source=" + PATH_TO_DATABASE;
if (!File.Exists(PATH_TO_DATABASE)) return;
using (SQLiteConnection connection = new SQLiteConnection(CONNECTION_STRING))
{
connection.Open();
using (SQLiteCommand command = new SQLiteCommand("SELECT id, name, host, path FROM moz_cookies", connection))
{
using (SQLiteDataReader read = command.ExecuteReader())
{
while (read.Read())
{
string id = read[0].ToString();
string name = read[1].ToString();
string host = read[2].ToString();
string path = read[3].ToString();
Console.WriteLine("ID: " + id);
Console.WriteLine("Name: " + name);
Console.WriteLine("Host: " + host);
Console.WriteLine("Path: " + path);
}
}
}
}
}
}
我正在为 Sqlite v. 3.6.23.1 使用 .Net Wrapper DLL。该应用程序的目标框架是.Net 2.0。
使用名为 SqliteExpert 的应用程序,我能够毫无问题地打开 sqlite 数据库。
如果有人有想法,那就太好了!
问候,鲍里斯