2011-01-19 123 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"/>