2012-12-10 102 views
0

我的數據庫(SQL精簡版)的密碼是Y6K<dkq2J)[hf/',@K"!IiQA 當我創造它的實體數據模型連接字符串中我的應用程序的配置將是:使用符號(「),並在數據庫連接字符串號(')

編輯

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

有報價跡象"和密碼',每一件事情是OK.so我想用Ado.Net SqCelconnection

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

如何更換"標誌和密碼'標誌?

我已經試過\",\"\",&quot;對於"標誌。

and '' and &apos; for ' sign.but does not work。

+1

檢查更新3以下答案:http://stackoverflow.com/a/3177871/55209 –

+0

你必須選擇。第一個使用不同的密碼,第二個使用轉義字符。 –

+0

@Ramhound:我不會改變通 – KF2

回答

2

你可能不得不做出,因爲字符串中的逃生和引號字符的自己的字符串。

這似乎工作:

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(); 
+0

謝謝你,但是'sb.Append(@」 Y6K KF2

+1

@irsog爲了正確性而更新,即使在看它時也要破解密碼。:-) – LarsTech

+0

:哈哈,再次感謝你。你保存了我 - ) – KF2