1
Answer

error occurred when insert data

Photo of Ashish Hada

Ashish Hada

7y
157
1
System.Data.SqlServerCe.SqlCeException occurred
HResult=0x80131501
Message=The database file may be corrupted. Run the repair utility to check the database file. [ Database name = \\?\C:\Users\Ashish Singh Hada\Documents\Visual Studio 2010\Projects\Medi Master\Medi Master\bin\Debug\MMDB.mdf ]
Source=SQL Server Compact ADO.NET Data Provider

Attachment: CreateUser.zip

Answers (1)

0
Photo of Tapan Patel
NA 8.1k 101k 7y
As per the error provided, you are using SQL CE and there is a good article (https://technet.microsoft.com/en-us/library/ms172420.aspx) to clean up the corrupted rows (which leads to above error).
Before you go with below approach, make sure to back up your database so that you won't loose any data if needed.
try writing small console app with below code 
 
  1. SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");  
  2.   
  3. if (false == engine.Verify())  
  4. {  
  5.    MessageBox.Show("Database is corrupted.");  
  6.    engine.Repair(null, RepairOption.RecoverAllorFail);  
  7. }