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>
Connection strings go inside a <connectionStrings> element. The traditional place to put <connectionStrings> seems to be immediately before <appSettings> but its precise location shouldn't matter.
Special characters can be escaped by encapsulating them in curly brackets {...}. When there is an un-escaped special character in the ODBC connection string the software will raise an error similar to: "Format of the initialization string does not conform to specification starting at index 90."
The connection strings are mostly stored in web. config. It means that connection specific information such as database name, username, and password are stored as a clear text in a file. This is definitely a security concern for your Production servers.
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="C:\Projects\Provider's.Tests\app_data\db.mdf;"
You should encode both the quotation marks and apostropes. Quotation marks (") are encoded using "
and apostrophes (') are encoded using '
. 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="C:\Projects\Provider's.Tests\app_data\db.mdf";Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
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="C:\Projects\Provider's.Tests\app_data\db.mdf";Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With