访问SQLite文件时出错

时间:2010-10-14 23:49:33

标签: vb.net sqlite

我用过

http://sqliteadmin.orbmu2k.de/

创建我的sqlite db文件。我创建它作为sqlite db版本3文件。

当我打开连接时

Dim Connection As New SQLite.SQLiteConnection(DATABASE_FILE_LOCATION)
Connection.Open()

我在Open()调用

上遇到此异常

“打开的文件不是数据库文件 文件已加密或不是数据库“(System.Data.SQLite.SQLiteException)异常消息=”打开的文件不是数据库文件\ r \ n文件已加密或不是数据库“,Exception Type =”System.Data .SQLite.SQLiteException“

这是什么问题?这是我的文件文件位置常量:

Private Const DATABASE_FILE_LOCATION As String = "Data Source=C:\Users\Scott\Desktop\Projects\Funds\Program\BudgetManager\Main.s3db;Version=3;"

2 个答案:

答案 0 :(得分:1)

你可以将这个c#改编为vb:

private void showTables()
{
   SQLiteConnection cn = new SQLiteConnection("Data Source=myDatabase.db3");
   try
   {
        cn.Open();
        cn.SetPassword("MyPassword");
        DataTable tables = cn.GetSchema("Tables");
        Console.WriteLine("I have {0} tables", tables.Rows.Count);
        cn.Close();
   }
   catch (SQLiteException ex)
   {
       Console.WriteLine(ex.ToString());
   }
}

您的数据库是否有密码? 您可以通过更改字符串告诉数据库您有密码:

SQLiteConnection cn = new 
SQLiteConnection("D:\Programming\Test\myDatabase.db3;Password=mypassword");

请务必仔细检查是否已安装所有内容(http://sqlite.phxsoftware.com/)并且您对此数据库文件拥有正确的权限。

如果您确定文件未加密,请重新安装http://www.sqlite.org/cvstrac/wiki?p=ManagementTools

答案 1 :(得分:0)

使用此代码: - 这段代码非常适合我

Private Sub CreateDatabase()

    Dim con As SQLiteConnection
    Dim cmd As SQLiteCommand

    Try
        'Create a new database connection
 Dim CONNECTION_STR as String = "Data Source= yourdatabase.sqlite;Version=3;New=False;"
        con = New SQLiteConnection(CONNECTION_STR)

        'Open the connection
        con.Open()

        'Create a new SQL command
        cmd = con.CreateCommand()
        con.Close()
        MsgBox("Database Created Successfully")
    Finally
        'Cleanup and close the connection
        If Not IsNothing(con) Then
            con.Close()
        End If
    End Try

End Sub