views:

370

answers:

4

I have the following connection string, and you will notice "Provider's.Tests", notice the single quote, how do I enter this in to the web.config to make it valid?

<connectionStrings>
    <clear/>
    <add name="Provider" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Projects\Provider's.Tests\app_data\db.mdf";Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
+5  A: 

I don't think its the Provider's that is the problem, It is the double quotes around the path.
Try to just remove it so it says AttachDbFilename=C:\Projects\Provider's.Tests\app_data\db.mdf;

If it is important in the connection string to have it, try encoding it: AttachDbFilename=&quot;C:\Projects\Provider's.Tests\app_data\db.mdf;&quot;

awe
A: 

you should use ' for the apostrophe and &quot ; for quotes for using special characters like this in the web.config file.

However, as other's have suggested you just need to remove the quotations as they are not required.

James
+1  A: 

The single quote is not a problem in your case. It's the double quotes you have around the filename. You can escape it like this:

<add 
    name="Provider" 
    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\Projects\Provider's.Tests\app_data\db.mdf&quot;;Integrated Security=True;User Instance=True" 
    providerName="System.Data.SqlClient"/>
Darin Dimitrov
A: 

You should encode both the quotation marks and apostropes. Quotation marks (") are encoded using &quot; and apostrophes (') are encoded using &apos;. The main issue here is the quotation marks, it might still work without encoding the apostrophes as you use quotation marks around the values.

<connectionStrings>
    <clear/>
    <add name="Provider" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=&quot;C:\Projects\Provider&apos;s.Tests\app_data\db.mdf&quot;;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Guffa