1
Vote

Database corruption

description

Newer version of the application uses following class to store into database
    public class DBObject
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }

    public void InsertIntoDB()
    {
            using(var db = OdbFactory.Open("NDB.db"))
            {
                DBObject dbobj = new DBObject();
                dbobj.Name = "My Name";
                dbobj.Description = "My Description";
                db.Store(dbobj);
            }
    }
Older version of the application had following class definition
    public class DBObject
    {
        public string Name { get; set; }
    }
When a database created using newer application is read in older application exception is thrown and database gets corrupted. Also newer application cannot read the database after it is opened once in older application.
Following is the code to read the database
    public void ReadFromDB()
    {
            using (var db = OdbFactory.Open("NDB.db"))
            {
                IList<DBObject> oblist = db.QueryAndExecute<DBObject>().ToList();
            }
    }

comments