1

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.

4
  • 1
    What is the exact exception text? Commented Jul 24, 2013 at 9:29
  • "unable to open database file" this is what i get from Exception.message If you need more info i will give you Commented Jul 24, 2013 at 9:30
  • Can you open it in another program which can open SQLite Databases? Like the Firefox plugin. Commented Jul 24, 2013 at 9:32
  • no i am applying lock(){ Insert statements} on it. only my application using that file. But i have two application 1st is windows service and 2nd is Windows application. How will i know weather file is using in another application. and i can open it in sqliteExpert Commented Jul 24, 2013 at 9:35

1 Answer 1

3

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();
    ...
}
Sign up to request clarification or add additional context in comments.

8 Comments

Connection String is Data Source= FilePath;Version=3;New=false;Compress=True;
@Pratik, as I stated in #3, I doubt the connection string is your problem. And it's not that likely you don't have Write permissions. The most likely suspect is an SQLiteConnection object that wasn't disposed of properly because you didn't use it properly. Make sure you're connecting (as I showed you) and doing your work inside the using statement at all times.
Is there any way to know weather sqlite connection is already open using another thread or process?
@Pratik, yeah, with a memory profiler. You'd be able to see an undisposed object.
ok thanks for that. and i am using this code: if (connection != null && connection.State == ConnectionState.Open) { connection.Close(); //connection.Dispose(); } In finally block.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.