3

I'm just beginning to use Linq-to-SQL and it's just wonderful to use. The problem is, this software is going to be run on a lot of machines and each machine will have a unique connection string.

Is there a way for me to manually set the connection the Linq-to-SQL (.dbml) uses?

The way I'm doing things now is creating the .dbml file, and in the graphic designer I'm dragging tables from the Server Explorer to the white board of the .dbml.

1 Answer 1

6

Yes. Just pass the connection string you want to use to the DataContext constructor:

MyDbContext _context = MyDbContext(connString);
Sign up to request clarification or add additional context in comments.

2 Comments

This is so great! What would happen is the .dbml recieves a connection string, but a table in the database has 2 more fields than it was expecting. What would occur?
@Sergio Tapia - LINQ to SQL would just ignore the extra columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.