How can I prevent "the objects that you add to the constructor are using another connection to transfer data ..."?

I am using Visual Studio 2010, and I have a LINQ to SQL DBML file that my colleagues and I use for this project.

We have a connection string in the web.config file that uses DBML. However, when I drag a new table from my "Server Explorer" into the DBML file ... I see a dialog box that requires one of these two options:

  • Allow visual studio to change the connection string to match the one in my solution explorer.
  • Cancel the operation (this means that I am not getting the table).

It’s not very difficult for me to discuss why the PM / devs who created this tool did not allow the third option - "Create an object anyway - don’t worry, I'm a developer!"

What I think would be a good solution if I can create a connection in Server Explorer - WITHOUT MASTER. If I can just insert a connection string, that would be awesome! Because then the DBML developer will not worry about me: O)

If someone knows the answer to this question or how to do it, please let us know!

+6
visual-studio-2010 linq-to-sql
source share
2 answers

Here is a similar thread that has a couple of options. Unfortunately, they all work a little, but this seems like the best solution to the problem. Managing various developer connection strings in LINQ to SQL

+1
source share

Suppose you are a SampleDataContext class. Create another file, for example, SampleDataContext.cs and add the following

 public partial class SampleDataContext { partial void OnCreated() { Connection.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQL"]; } } 

So, now it doesn’t matter which database connection you use in the designer; the used connection string will be pulled from the settings of your application.

0
source share

All Articles