Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read a .db file in C#

 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

like image 573
Co Koder Avatar asked Jun 13 '12 18:06

Co Koder


2 Answers

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/

like image 113
tcarvin Avatar answered Oct 05 '22 22:10

tcarvin


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.

like image 22
Jason Meckley Avatar answered Oct 05 '22 22:10

Jason Meckley