Skip to main content

Posts

Showing posts from September, 2010

Google Search

Custom Search

Live Search

Yahoo Search


Search the web Search this site

Repairing a Corrupted Database

When we are regularly using databases, sometimes those will get corrupted. This happened to one of my applications, it was a Windows Mobile application with SQL Server CE database. Since it is running in a mobile it is bit difficult for us to fix the database using the desktop machine. I used the following .Net Compact framework code to fix the corrupted database while the database is in the mobile.



privatevoid btnRepair_Click(object sender, EventArgs e) {Cursor.Current = Cursors.WaitCursor;Cursor.Show();// txtDBPath will contain the path to the database.     engine = newSqlCeEngine(@"Data Source=" + txtDBPath.Text + ";Password=DBPassword");try     {if (!engine.Verify())         {Cursor.Current = Cursors.Default;Cursor.Hide();DialogResult result = MessageBox.Show("Database is corrupted. Do you want to repair?", "My App", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);if (result == DialogResult.Yes)            …