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

Dave Ziegler
  • 1,737
  • 3
  • 19
  • 36
Co Koder
  • 2,021
  • 7
  • 31
  • 39
  • 3
    Does the C# process have permissions to read that file? – Eric J. Jun 13 '12 at 18:54
  • Did you see this? http://www.connectionstrings.com/paradox "Please note that you should only specify the folder where the database resides. Not the database name itself." – Dave Ziegler Jun 13 '12 at 18:55
  • 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 '12 at 18:58
  • 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? – Hector Sanchez Jun 13 '12 at 18:59
  • And the people table/view exists in that file, correct? – Dave Ziegler Jun 13 '12 at 19:00
  • Did you spell it correctly? It's not poeple or something, is it? :-) – Dave Ziegler Jun 13 '12 at 19:02
  • Yes, the name is exactly "people", I also checked by using sqlite database browser – Co Koder Jun 13 '12 at 19:04
  • MSDN mentions service pack 5, do you have the latest applied? – mgnoonan Jun 13 '12 at 19:08
  • What do you mean exactly, I have not done anything, I am just trying to run that program – Co Koder Jun 13 '12 at 19:09
  • http://support.microsoft.com/kb/230126/EN-US/ – mgnoonan Jun 13 '12 at 19:10
  • That looks like it only applies to modifications, not reads: "Without Jet 4.0 SP5 or a later version or the BDE, Paradox data can be read, imported and exported, or linked to as read-only." – Dave Ziegler Jun 13 '12 at 19:13
  • I have checked my system folder which is Windows\SysWOW64 and Msjet40.dll is over there already.... – Co Koder Jun 13 '12 at 19:20
  • So it seems you should definitely leave the file name out of Path, because then you can at least connect. Now the issue is: where is your people table? It's not something silly like case-sensitivity is it? people vs. PEOPLE? – Dave Ziegler Jun 13 '12 at 19:21
  • Nope, if you want me to send screenshot, I can send it – Co Koder Jun 13 '12 at 19:30
  • Couldn't hurt, attach some screen shots. We might see something you missed. – Dave Ziegler Jun 13 '12 at 19:32
  • 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 '12 at 19:50
  • That's what I was wondering, thought I missed something. – Dave Ziegler Jun 13 '12 at 19:51
  • Please look at carefully the toll bar of the screen shot , it says /Database/Mydatabase.db not .sqlite. I just opened by using sqlite browser – Co Koder Jun 13 '12 at 19:54
  • Why did you blur out the drive letter in the screen shot, your Path is @"c:\Database\Mydatabase.db", you're not actually working on d:\Database\ are you? – Dave Ziegler Jun 13 '12 at 20:08
  • ohh that thing, I just tried another thing by moving the database file from c to e, and I did not want you guys are mixed up, I am working on c directory – Co Koder Jun 13 '12 at 20:13
  • if you want to try it in your computer, I also can upload the database file – Co Koder Jun 13 '12 at 20:14
  • 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 '12 at 20:18
  • Upload the db file somehwre if possible – tcarvin Jun 13 '12 at 20:57
  • https://rapidshare.com/files/3058883180/Mydatabase.db – Co Koder Jun 13 '12 at 21:09

4 Answers4

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.

Jason Meckley
  • 7,589
  • 1
  • 24
  • 45
  • 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](http://msdn.microsoft.com/en-us/library/wyts434y.aspx) of configuration for exactly this situation. – Joseph Yaduvanshi Jun 13 '12 at 19:02
  • I haven't ever used that config option before. thanx for pointing that out. – Jason Meckley Jun 13 '12 at 19:04
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/

tcarvin
  • 10,715
  • 3
  • 31
  • 52
  • Yes, that is correct, but it has .db file extension, is it called paradox file or sqlite file ? – Co Koder Jun 14 '12 at 01:43
  • 1
    It is not a Paradox file so you cannot connect to it with a the Jet OLEDB provider. – tcarvin Jun 14 '12 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 '12 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. :-) – Dave Ziegler Jun 14 '12 at 18:02
1

Try one of these connection strings instead.

Dave Ziegler
  • 1,737
  • 3
  • 19
  • 36
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.

mgnoonan
  • 7,060
  • 5
  • 24
  • 27
  • 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 '12 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 '12 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 '12 at 19:12
  • So you didn't try it with just `@"C:\Database"`? – mgnoonan Jun 13 '12 at 19:14
  • I tried it and 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 '12 at 19:17
  • My understanding is that where you have `people` should be the name of the file, so perhaps you should change your query to `select * from mydatabase`. – mgnoonan Jun 13 '12 at 19:23
  • 1
    If I changed as you said, How can C# find which table is gonna be used ? – Co Koder Jun 13 '12 at 19:26
  • The filename is the tablename. So the JET engine takes the "tablename" and looks for a file with the same name and the extension ".db". – mgnoonan Jun 13 '12 at 20:30
  • So, Should I change the file name "Mydatabase.db" to "people.db" ? – Co Koder Jun 13 '12 at 20:34
  • when I change the file name, i am getting that error External table is not in the expected format. – Co Koder Jun 13 '12 at 20:41
  • Well, that means it found the file. I'm back to recommending you install the Jet 4.0 SP5. – mgnoonan Jun 13 '12 at 21:40
  • 1
    Hmmm... http://bettereducation.com.au/it/yaf_postst1430_C-External-Paradox-table-is-not-in-the-expected-format.aspx – Dave Ziegler Jun 13 '12 at 21:46