views:

121

answers:

1

In a WPF application I use LINQ to SQL, SQL Server 2008.

SQL Server computer was replaced and SQL Server was installed under instance name not the same as before. Database was restored under the same name as before.

The new connection string was added to the application.

But it appeared that it is impossible for the application to connect to db due to the new instance name. The LINQ to SQL datacontext required to be updated. The problem was solved only after tables were deleted and then again added in the project's LINQ datacontext .dbml page.

Is there a way to change SQL Server instance name without the necessity to edit project in Visual Studio?

+1  A: 

Instance name is present only in the connection string. Are you sure that you use the same connection string name in DBML file properties and in web.config? When you connect your server explorer to new database in visual studio and drag the tables to DMBL file, then the new connection string name is created for DBML datacontext - the connection string present in web.config is not used any more. The valid connection string name is visible in properties view after right click on DBML design space.

PanJanek
Yes, for sure that's the case, thanks! Is there a way to change the connection string in the properties of DBML file programmatically, in order to create an interface for user to set database connection by himself? +1
rem
In such case the best solution is to pass connection string as a parameter of DataContext constructor (new MyDataContext(connectString)).
PanJanek