Monday, 6 January 2014

Create Connection String using database name with a space


Below is a simple point but can be easily missed out. To stop wasting time on troubleshooting, I thought of adding this to my blog.                      

As an example here is my database name ‘Production Test’. If I need to create a connection string calling this DB, I need to use " surrounding the DB name in web config or app config file in Visual Studio in order to avoid connection string errors.
"  represents   quotation mark (U+0022)

<connectionStrings>

<add name="Name.Properties.Settings.TESTConnectionString"
connectionString="Data Source=server\test;
Initial Catalog=&quot;Production Test&quot;;Integrated Security=True" providerName="System.Data.SqlClient" />

</connectionStrings>

Enjoy escape “ quotation mark (U+0022)

No comments:

Post a Comment