1

In the following code for a C#.Net windows/desktop application, I have given wrong password while connecting to database but message box still displays Open.

SQLiteConnection conn = new SQLiteConnection("Data Source=DMB.sqlite;Version=3;");
conn.SetPassword("password");
conn.Open();
conn.Close();
conn = new SQLiteConnection("Data Source=DMB.sqlite;Version=3;Password=cdssss;");
conn.Open();
MessageBox.Show(conn.State.ToString());

Why it is still open when password is wrong?

Neetu
  • 117
  • 1
  • 13
  • Are you using some fork of sqlite? It doesn't use passwords... – Shawn Oct 17 '18 at 07:20
  • 1
    @OP There is a comment on the accepted answer [here](https://stackoverflow.com/a/24349415/3181933) that "with no password provided, Open() will NOT fail on a password-protected SQLite database, as you would expect! What fails is any subsequent data or metadata operation on that open file." - Is that perhaps what's happening in your case? – ProgrammingLlama Oct 17 '18 at 07:22

1 Answers1

0

This behavior is by design in the .net sqlite driver:

This is by design. The error message only occurs when you try to read from -OR- write to the underlying database file. Opening the database does not typically perform either operation.

It is recommended that you execute a SELECT statement on some well-known table (e.g. "sqlite_master") immediately after opening the database in order to determine if it is in a usable state.

Cited from Ticket 3eb097e917a7740f3499aae66e9a3cd021e9f81c:

https://system.data.sqlite.org/index.html/tktview/3eb097e917a7740f3499

Fildor
  • 14,510
  • 4
  • 35
  • 67