-2

My project has a reference to SQLite.Interop.066.dll and even after putting in the correct path to the SQLite database, the application is still unable to find it. A SQLiteException was unhandled is returned.

        SQLiteConnection conn = new SQLiteConnection();
        //SQLiteDataAdapter da;
        SQLiteCommandBuilder cb;
        DataTable dt=new DataTable();
        int row = 0;

        conn.ConnectionString = "Data Source=C:\\database\\info.db; Version=3";
        conn.Open();

        DataRow dr = dt.NewRow();
        dr["name"] = txtName.Text;
        dr["address"] = txtAddress.Text;
        dr["phone"] = txtPhone.Text;
        dr["position"] = txtPosition.Text;
        dt.Rows.Add(dr);
        da.Update(dt);

        row = dt.Rows.Count - 1;
        txtName.Text = dt.Rows[row]["name"].ToString();
        txtAddress.Text = dt.Rows[row]["address"].ToString();
        txtPhone.Text = dt.Rows[row]["phone"].ToString();
        txtPosition.Text = dt.Rows[row]["position"].ToString();

        da.Fill(dt);

        cb = new SQLiteCommandBuilder(da);

        conn.Dispose();
        conn.Close();

The exception occur at line: conn.Open();
sorry for the mistake title error before...

rose
  • 29
  • 2
  • 7

2 Answers2

1

Take a look at the proper format for a SQLite connection string which can be found here: http://www.connectionstrings.com/sqlite.

At first blush, it looks like you are missing the file extension on "info" and any necessary connection string options that might be appropriate for your implementation (again, see connectionstrings.com for help here).

Since the error is an "index out of range" exception being thrown by conn.Open() it sounds as though it is just unable to find the database, and fixing the extension might just do the trick.

Michael Kingsmill
  • 1,815
  • 3
  • 22
  • 31
  • I am not a SQLite expert, but from looking at the examples on `connectionStrings.com` and doing some Google searching, it appears that you are required to include the `Version` clause to the connection string. Also, make sure that your database is version 3 or higher, as it appears version 2 does not work with the `System.Data.SQLite.SQLiteConnection` object you are using. – Michael Kingsmill Nov 26 '11 at 02:21
  • i'm sure my sqlite ado.net database is version 3 above – rose Nov 26 '11 at 02:38
  • i already have a look that sqlite ado.net is version 3.6.23.1 – rose Nov 26 '11 at 03:55
0
conn.ConnectionString = "Data Source=C:\\database\\info.db; Version=3;"; 
Taryn
  • 242,637
  • 56
  • 362
  • 405
tknuslu
  • 11