In my application i used Linq to Sql class i.e dbml class.In linq by default DataContext object read connection string from application setting and Stored this also in App.config as a reference copy from “Application Settings”.
However when I run the application from debug folder on my PC, it runs correctly, but when I change the connection string i.e server name of YourApplicationName.exe.config then try to run it an error message say that connection related problem bla bla….
So i think when i will deploy this client side then i will again face same problem.
But i have gotten solution for this problem.
If anybody follow this step then every problem will be solved.
1. Open up the LINQ to SQL designer, and open the Properties tab of the designer ,expand Connection and set Application Settings to False. Save.
2. Close that down and open up your DataContext designer file (dbml_name.designer.cs) and alter the DataContext constructor. You will immediately notice how your connection string decided to jump in here as you turned off application wide settings. So the part to focus on here is altering the base() inheritor. Renaming “MyConnString” below to suit your own. You will also need a reference to System.Configuration:
* public dbDataContext() : base(ConfigurationManager.ConnectionStrings[“MyConnString”].ConnectionString, mappingSource)
3. Open the App.config or Web.config featured in the project where your LINQ to SQL classes reside, and rename the connection string to what you defined as “MyConnString“.
4. You now must Cut the entire entry with name change and Paste it into the main App.config or Web.config of the application which is to access the data, such as a web application, Silverlight, WPF, WCF etc.
5. Now Right Click and open the Properties on your DAL or project containing your LINQ to SQL classes and remove the connection string “Application Setting” reference on the Settings tab.
ref:Get Connection String from app.config
If you have any query please leave a comment.