代码之家  ›  专栏  ›  技术社区  ›  Scott

访问SQLite文件时出错

  •  0
  • Scott  · 技术社区  · 16 年前

    我用过

    http://sqliteadmin.orbmu2k.de/

    当我打开连接时

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

    “打开的文件不是数据库文件 文件已加密或不是数据库(System.Data.SQLite.SQLite Exception)Exception Message=“打开的文件不是数据库文件\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 回复  |  直到 16 年前
        1
  •  1
  •   Junior Mayhé    16 年前

    你可以把这个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

        2
  •  0
  •   Sushil Saini    13 年前

    使用此代码:- 这段代码对我来说是完美的

    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
    
    推荐文章