Search code examples
c#oledbdbf

Read a dbase IV file C#


I am developing an application to recover data from a DBF file.

I did research on the Internet that sent me to this link : enter link description here

I applied this code but nothing helps it doesn't work :/

            string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Test\users.dbf;Extended Properties=dBASE IV;User ID=;Password=MyPassword;";
            using (OleDbConnection con = new OleDbConnection(constr))
            {
                
                var sql = "select * from users.dbf";
                OleDbCommand cmd = new OleDbCommand(sql, con);
                con.Open();
                DataSet ds = new DataSet(); ;
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                da.Fill(ds);
            }

I pass this code in a Try and Catch and it returns me this error: Unable to start your application. The workgroup information file is missing or opened exclusively by another user. the error is caused when trying to open the connection. However the file is neither opened nor used by anyone else.

thank you in advance ;)


Solution

  • Try to remove the file name in the connection string. According to the documentation, The "Data Source" property should only contain the path.

                string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Test;Extended Properties=dBASE IV;User ID=;Password=MyPassword;";