views:

988

answers:

4

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.

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

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.

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?

+2  A: 

If I understand your problem correctly, you simply change the database's connection string in your app.config / web.config.

Edit, 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 :)

Omer van Kloeten
A: 

I believe you can store the connection information in an app.config file and retrieve it from there. Here 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.

VanOrman
+1  A: 

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.

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: detect local

And go from there to set the appropriate connection string based on the results.

KevDog
+1  A: 

A more useful answer...

app.config ends up as appname.exe.config when it has been built.

rather than opening Visual Studio and modifying app.config, you can simply edit the appname.exe.config file, and restart the app.

TheoJones