Exception changing password of existing SQL Server CE database

0

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://docs.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)

sql-server-ce
sql-server-ce-4
asked on Stack Overflow Jan 27, 2021 by dan • edited Jan 27, 2021 by marc_s

1 Answer

0

Hmmm OK it is working now.

var updatePasswordConnStr = "DataSource=; password=newPass;";
answered on Stack Overflow Jan 28, 2021 by dan

User contributions licensed under CC BY-SA 3.0