2011-01-19 260 views
4

我正在寫入以下連接字符串到web.config ,但它給了我錯誤。什麼是寫它的正確方法?雙引號內的雙引號

<add name="stargaze_stargazeConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="D:\Work At DS\19th Jan\myastrolove.com_new\App_Data\dbName.mdf";Integrated Security=True;User Instance=True"/> 

回答

14

web.config文件是XML,所以你需要躲避內引號&quot;

<add name="stargaze_stargazeConnectionString1" 
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;D:\Work At DS\19th Jan\myastrolove.com_new\App_Data\dbName.mdf&quot;;Integrated Security=True;User Instance=True"/> 
2

裏面的字符串,用\"取代"正確逃避它。

這意味着,你的字符串應該是這樣的:

"<add name=\"stargaze_stargazeConnectionString1\" connectionString=\"Data Source=.\SQLEXPRESS;AttachDbFilename=\"D:\Work At DS\19th Jan\myastrolove.com_new\App_Data\dbName.mdf\";Integrated Security=True;User Instance=True\"/>" 
+0

-1 - 它不是C#字符串 - 它在web.config中。這仍然會產生OP的錯誤。 – Oded 2011-01-19 12:06:09

+0

似乎我誤解了這個問題。我沒有看到web.config部分。這會讓你的答案正確,所以我會加倍努力。 – 2011-01-19 12:10:40

-1

它不應該是這樣:

<add name="stargaze_stargazeConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=\"D:\Work At DS\19th Jan\myastrolove.com_new\App_Data\dbName.mdf\";Integrated Security=True;User Instance=True"/>