gofor.net
gofor.net

Reputation: 4298

double quotes inside double quotes

i am writing the following connection string into web.config but it giving me error.what is the correct way to write it?

<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"/>

Upvotes: 4

Views: 5219

Answers (3)

Oded
Oded

Reputation: 499262

web.config is XML, so you need to escape the inner quotes to &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"/>

Upvotes: 14

WizKid
WizKid

Reputation: 4908

Shouldn't it be like:

<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"/>

Upvotes: -1

&#216;yvind Br&#229;then
&#216;yvind Br&#229;then

Reputation: 60724

Inside the string, replace " with \" to properly escape it.

That means that your string should look like this:

"<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\"/>"

Upvotes: 2

Related Questions