开发者

How can I prevent 'objects you are adding to the designer use a different data connection...'?

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

We have a connection string in the web.config file that the DBML is using. However, when I drag a new table from my "Server Explorer" onto the DBML file... I get presented with a dialog that demands that do one of these two options:

  1. Allow visual studio to change the connection string to match the one in my solution explorer.
  2. Cancel the operation (meaning, I don't get my table).

I don't really care to开发者_Go百科o much about the debate as why the PMs/devs who made this tool didn't allow a third option - "Create the object anyway - don't worry, I'm a developer!"

What I am thinking would be a good solution is if I can create a connection in the Server Explorer - WITHOUT A WIZARD. If I can just paste a connection string, that would be awesome! Because then the DBML designer won't freak out on me :O)

If anyone knows the answer to this question, or how to do the above, please lemme know!


Here is a similar thread that has a couple of options. Unfortunately all of them are a bit of a work around, but it seems like the best current solution to the problem. Managing different developer's connection strings under LINQ to SQL


Suppose you are generatung a SampleDataContext class. Create another file, say called SampleDataContext.cs and add the following

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

So now it does not matter which database connection you use in the designer; the connection string to be used will be pulled from your app settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜