5
 string Path = @"c:\Database\Mydatabase.db";

     string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Paradox 5.x;";

    // Define the database query    
    string mySelectQuery = "SELECT id,name FROM people WHERE id < 3;";

    // Create a database connection object using the connection string    
    OleDbConnection myConnection = new OleDbConnection(myConnectionString);

    // Create a database command on the connection using query    
    OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

    // Open the connection    
    myCommand.Connection.Open();

    // Create a database reader    
    OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

The Error is at myCommand.Connection.Open(); and it says: 'c:\Database\Mydatabase.db' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

I am trying to read a .db file in C#. However, I am getting an error, I am sure that file is located there, the error does not make sense for me. Could you please help me ? Or How can I read a .db(paradox) database file in C# ?

EDIT: string Path = @"c:\Database\";

The Error for this case is "The Microsoft Jet database engine could not find the object 'people'. Make sure the object exists and that you spell its name and the path name correctly."

If I change it like that, How can C# find which database file is gonna be used ? Since, I did not specify file name which is "Mydatabase.db" at anywhere

enter image description here

24
  • 3
    Does the C# process have permissions to read that file?
    – Eric J.
    Jun 13, 2012 at 18:54
  • Did you see this? connectionstrings.com/paradox "Please note that you should only specify the folder where the database resides. Not the database name itself." Jun 13, 2012 at 18:55
  • 1
    but that error, sound that the connection could be made sucesfully, and the people table doesn't exists, maybe you are missing the user/schema or something? Jun 13, 2012 at 18:59
  • 1
    Probably a silly question, but your screen shot show its an SQLite database, while your code is going after a Paradox database?
    – tcarvin
    Jun 13, 2012 at 19:50
  • 1
    Like I siad, it might have been a silly question. But the program title says "SQLite Database Browser". And file extension is meaningless. I routinely mangle my db file extensions to avoid nosey customers from peering inside.
    – tcarvin
    Jun 13, 2012 at 20:18

4 Answers 4

2

Confirmed it is an SQLite database, I just downloaded it on my phone and viewed it with an SQLite viewer.


You will need to download an ADO.NET provider for SQLite:

"Official" version (from SQLite, not MS)

http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki

Older version

http://sqlite.phxsoftware.com/

4
  • Yes, that is correct, but it has .db file extension, is it called paradox file or sqlite file ?
    – Co Koder
    Jun 14, 2012 at 1:43
  • 1
    It is not a Paradox file so you cannot connect to it with a the Jet OLEDB provider.
    – tcarvin
    Jun 14, 2012 at 12:31
  • 1
    Ok, I have installed that, Could you provide an example how to read sqlite database in C# ?
    – Co Koder
    Jun 14, 2012 at 16:08
  • "Could you provide an example how to read sqlite database in C#" -- That is a separate topic. You should give it a shot and post a new question if you get stuck. :-) Jun 14, 2012 at 18:02
2

if the application cannot see the file than chances are it's a security issue. while "you" can access the file. the application cannot.

is this a web application? if so, then this is the problem. asp.net/IIS cannot see outside of its virtual directory. In which case you either need to elevate/modify privileges of the asp.net user account to access the file, or move the database file within the virtual directory. This is a good candidate for the App_Data directory.

2
  • 1
    +1. I think you're correct about permissions, but incorrect about 'asp.net/IIS cannot see outside of its virtual directory' unless you change permissions of the asp.net user account. Nearly everything can be done via web.config or machine.config without changing the actual account. MSDN has an example of configuration for exactly this situation. Jun 13, 2012 at 19:02
  • I haven't ever used that config option before. thanx for pointing that out. Jun 13, 2012 at 19:04
1

Try one of these connection strings instead.

0

According to this site, you should only specify the folder name, not the db file.

Please note that you should only specify the folder where the database resides. Not the database name itself.

The linked MSDN article says that Jet 4.0 Service Pack 5 should be used if you want to update the data, otherwise it may be read-only. In any case I would recommend installing the service pack.

12
  • I have also tried that , It does not work... I am getting that error The Microsoft Jet database engine could not find the object 'people'. Make sure the object exists and that you spell its name and the path name correctly.
    – Co Koder
    Jun 13, 2012 at 18:59
  • That is relevant information that should have gone in the question. Is there a 'people' table in that database file?
    – mgnoonan
    Jun 13, 2012 at 19:01
  • Just a curiosity, If i do not specify the folder name like "Mydatabase.db", How can C# find that file under specified folder ?
    – Co Koder
    Jun 13, 2012 at 19:12
  • 1
    If I changed as you said, How can C# find which table is gonna be used ?
    – Co Koder
    Jun 13, 2012 at 19:26
  • 1
    Hmmm... bettereducation.com.au/it/… Jun 13, 2012 at 21:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.