Make SQLite connection fail if database is missing? (deleted/moved)

前端 未结 6 521
终归单人心
终归单人心 2021-01-18 11:39

I have the following method inside class DBConnection. I call the method like this: SQLiteConnection conn = DBConnection.OpenDB(); when I want to o

6条回答
  •  别那么骄傲
    2021-01-18 12:35

    I haven't used SQLite but that is pretty bizarre behaviour to auto create a brand new database.

    You could just adjust your try block to do a Select top 1 * From Table immediately after you open the connection, if it works, throw away the result and continue to return your conn object. If it fails, the exception handler should fire.

提交回复
热议问题