<p>I am working on a winforms application using LINQ to SQL - and am building the app using a SQL Express instance on my workstation. The final installation of the project will be on a proper SQL Server 2005.  </p>

<p>The database has the same name, and all tables are identical but the hostname is different. </p>

<p>The only way I have found to make my app work from one machine to the next is to re-open the code in Visual Studio, delete all of the objects referring to the SQL express instance from my .mdbl, save the project, connect to the other server, drag all of the references back on, and rebuild the application for release once more.</p>

<p>an answer here suggested that one can simply modify the app.config/web.config file - whih would work for asp.net, but this is a winforms application. What's the correct way of making LINQ to SQL apps use a new database without having to re-open the app in visual studio?</p>

[{'answer_id': 49265, 'author': 'Omer van Kloeten', 'author_id': 4979, 'author_profile': 'https://Stackoverflow.com/users/4979', 'pm_score': 2, 'selected': True, 'text': "<p>If I understand your problem correctly, you simply change the database's connection string in your app.config / web.config.</p>\n\n<p><strong>Edit</strong>, post clarification: You have the connection strings stored somewhere. They might be in the app.config of your server. Still, you get them from somewhere and that somewhere may be in an app.config. Use that then :)</p>\n"}, {'answer_id': 49365, 'author': 'VanOrman', 'author_id': 4550, 'author_profile': 'https://Stackoverflow.com/users/4550', 'pm_score': 0, 'selected': False, 'text': '<p>I believe you can store the connection information in an app.config file and retrieve it from there.  <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3716857&amp;SiteID=1" rel="nofollow noreferrer">Here</a> is a post about doing that with LINQ to SQL.  Once you deploy it to a production server, you can just edit the XML to change the data source.</p>\n'}, {'answer_id': 108548, 'author': 'KevDog', 'author_id': 13139, 'author_profile': 'https://Stackoverflow.com/users/13139', 'pm_score': 1, 'selected': False, 'text': '<p>One good solution is to add another connection to the dbml file itself. You can get to this by right-clicking on the field of the design surface and selecting properties. From there, you can add another connection string. Instead of deleting everything and redragging, just change the string and recompile.</p>\n\n<p>But if you want to get fancy-schmancy, you can have the program auto-detect whether it is being run locally or not, using this neat utility function: <a href="http://dotnetperls.com/Content/Local-Detect.aspx" rel="nofollow noreferrer">detect local</a></p>\n\n<p>And go from there to set the appropriate connection string based on the results.</p>\n'}, {'answer_id': 161413, 'author': 'TheoJones', 'author_id': 5146, 'author_profile': 'https://Stackoverflow.com/users/5146', 'pm_score': 1, 'selected': False, 'text': '<p>A more useful answer...</p>\n\n<p>app.config ends up as appname.exe.config when it has been built.</p>\n\n<p>rather than opening Visual Studio and modifying app.config, you can simply edit the appname.exe.config file, and restart the app.</p>\n'}]
['https://Stackoverflow.com/questions/49260', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5146/']