Exception changing password of existing SQL Server CE database

273 Views Asked by At

Using SQL Server CE 4.0.8876.1 (NuGet package). I'm trying to change the password of an existing SQL Server CE database as per this article: https://learn.microsoft.com/en-us/previous-versions/sql/compact/sql-ce-3.0/reference/kt1a3805(v=vs.85)?redirectedfrom=MSDN

Perhaps I cannot change the password if the existing database is already encrypted?

var oldConnStr = "DataSource=\"C:\\temp\\FilePath.sdf\";Persist Security Info=False; 
password=oldPass; Encrypt Database=True; flush interval=1";
var updatePasswordConnStr = "DataSource=; password=newPass; Encrypt Database=True;";

using (var sqlCeEngine = new SqlCeEngine(oldConnStr))
{
    sqlCeEngine.Compact(null);
    sqlCeEngine.Compact(updatePasswordConnStr);
}

I keep getting the following exception when I call sqlCeEngine.Compact (both calls):

System.Data.SqlServerCe.SqlCeException
HResult=0x80004005
Message=The password specified for the source database is incorrect. [ Data Source = FilePath.sdf ]
Source=SQL Server Compact ADO.NET Data Provider

StackTrace:
at System.Data.SqlServerCe.SqlCeEngine.Repair(SEFIXOPTION option, String dstConnStr, RepairOption repairOption)

1

There are 1 best solutions below

0
dan On

Hmmm OK it is working now.

var updatePasswordConnStr = "DataSource=; password=newPass;";