Specify Linq To SQL ConnectionString explicitly

Posted by Michael Freidgeim on Geeks with Blogs See other posts from Geeks with Blogs or by Michael Freidgeim
Published on Sat, 14 Apr 2012 02:44:21 GMT Indexed on 2012/04/14 5:30 UTC
Read the original article Hit count: 169

Filed under:
When modifying Linq to  Sql data model in Visual Studio 2010,  it re-assigns ConnectionString that is available on developer’s machine.
Because the name can be different on different machines, Designer often replace it with something like ConnectionString1, which causes errors during deployment.
It requires developers to ensure that ConnectionString stays unchanged.
 
More reliable way is to use context constructor with explicit ConnectionString name instead of parameterless default constructor

GOOD:
  var ctx = new MyModelDataContext(Settings.Default.ConnectionString);
Not good:
         var ctx = new MyModelDataContext();

© Geeks with Blogs or respective owner