The specified password does not match the database password when connecting with SQL Server Compact 4.0

The specified password does not match the database password when connecting with SQL Server Compact 4.0

If you have a connection string syntax something like below, you will get this error while establishing a connecting with a SQL Server Compact 4.0 database.

using (SqlCeConnection connection = new SqlCeConnection(@"DataSource=C:\Database\CSharpCornerDB.sdf"))

I have looked around and did not find a quick answer. I expected Compact database similar to Access where you do not need a password. 

The problem here is a missing password in the connection string.

using (SqlCeConnection connection = new SqlCeConnection(@"Data Source=C:\Database\CSharpCornerDB.sdf;Password=maheshsharp"))

To confirm this, you can use SQL Server Compact Toolbox. When you try to connect to a database and use the Test button, if password is incorrect, you wil see this error.

SqlCe1.jpg

If you provide a correct password, you will see this message.

SqlCe2.jpg

Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.