0

My database(Sql compact edition) password is Y6K<dkq2J)[hf/',@K"!IiQA. When I create it's entity data model connection string in my App config will be:

Edited

<add name="OtherEntities" ... Password=&quot;&quot;Y6K&lt;dkq2J)[hf/',@K&quot;&quot;&quot;&quot;!IiQA&quot;&quot;  ... />

There are quotation sign " and ' in the password,every thing is OK.so i want to use Ado.Net SqCelconnection.

            string pass = "???";
            string conString =
                "Data Source=path\Other.sdf;password='" + pass + "';";
            using (SqlCeConnection connection = new SqlCeConnection(conString))
            {
.

How do I replace " sign and ' sign in password?

I already tried \",\"\",&quot; for " sign.

and '' and &apos; for ' sign.but doesn't work.

KF2
  • 9,887
  • 8
  • 44
  • 77

2 Answers2

2

You probably have to make the string yourself because of those escape and quote characters within the string.

This seemed to work:

StringBuilder sb = new StringBuilder();
sb.Append(@"Y6K<dkq2J)[hf/',@K");
sb.Append((char)34);
sb.Append("!IiQA");

string conString = @"Data Source=path\Other.sdf;password=" + sb.ToString();
LarsTech
  • 80,625
  • 14
  • 153
  • 225
0

Seems you may not be able to have single and double quotation marks in the same connections string.

Paul Ruane
  • 37,459
  • 12
  • 63
  • 82