简体   繁体   中英

unable to open database file in sqlite (using finisar.sqlite)

I am using sqlite database with sqlite.net dll in my application. Namespace is Finisar.sqlite I have problem while inserting entries in to database using transaction, It throws exception at open connection as "unable to open database file".

I google it but solutions are like change connection string. if i follow that process then finisar gives me exception as invalid params.

SQLiteConnection db = new SQLiteConnection(f_strConnStr);

db.Open();

**Valid parameters are:** 

Data Source=<database file>  (required)

Version=<version of SQLite (2 or 3)>            (default: 2)

New=True|False                  (default: False)

Compress=True|False                 (default: False)

UTF8Encoding=True|False             (default: False)

UTF16Encoding=True|False            (default: False)

Cache Size=<N>                  (default: 2000)

Synchronous=Full|Normal|Off             (default: Normal)

DateTimeFormat=ISO8601|Ticks|CurrentCulture     (default: ISO8601)

Compatibility=[old-date-format][,old-binary-format] (default: None)

I tried solution like pooling connection string, journal mode = off etc but nothing works for me. even i can not create file which is password protected due to invalid parameter.

I can not add other than this parameters. If anyone having solution regarding this issue please help us.

Thanks in advance.

So a number of things could be going wrong here:

  1. The folder the SQLite database is in, you don't have Write permissions to.
  2. The database is already open by another SQLiteConnection .
  3. The connection string is wrong. I think this one is unlikely because it's clearly a variable you're pulling the connection string from and I have to believe other times you wanted data you used the same string.

To remedy #2 you should always access your data like this:

using (SQLiteConnection c = new SQLiteConnection(f_strConnStr))
{
    c.Open();
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM