Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

Exception changing password of existing SQL Server CE database

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)

question from:https://stackoverflow.com/questions/65927213/exception-changing-password-of-existing-sql-server-ce-database

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hmmm OK it is working now.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...