PDA

Click to See Complete Forum and Search --> : [RESOLVED] Compact and Repair Error?


Jigabyte
Jan 8th, 2010, 05:06 AM
Hi Peeps,

Here is my code to compact and repair a SQLCE database:-

Dim sCompact As String = "Data Source=/Program Files/PocketAudit/PocketAudit_C.sdf; Password=jiga2007; Encrypt Database=True"
Dim database As New SqlCeEngine(CeLocalConnectionString)

If Not database.Verify Then
database.Repair(CeLocalConnectionString, RepairOption.DeleteCorruptedRows)
database.Compact(sCompact)
IO.File.Delete(CeDataBase)
IO.File.Move("/Program Files/PocketAudit/PocketAudit_C.sdf", CeDataBase)
End If

It would seem that there is a problem with the database because the verify fails and when it goes to database.repair it produces and error saying the database filename already exists. Is this because it is trying to recover the corrupt rows in a different database. I would of thought not.

Thanks for any help,

Jiggy!

Jigabyte
Jan 8th, 2010, 05:30 AM
Okay I have sorted my first problem by leaving the connection string blank; this simply repairs the database without outputing to a new file.

My next problem is once the repair is complete is seems to remove the password for the database; how can I add the password back?

Regards,

Roger

Jigabyte
Jan 8th, 2010, 06:11 AM
Managed to sort it; when you repair or compact you specify the datasource=; and then add the password as password=324234234; as the connection string

datasource=;password=43534345;

Hope this helps others!!!!